A keyword watcher is given a set of n keywords, then reads a stream of characters one at a time. After each character arrives, report Y if some keyword equals a suffix of the characters read so far, and N otherwise.
The standard trie approach stores the keywords reversed, so that after each new character you can walk backward through the recent characters. Keywords and the stream consist of lowercase English letters only.
Line 1: an integer n.
Line 2: n space-separated keywords.
Line 3: the stream, a non-empty string of lowercase letters.
A single line: a string of Y/N, one character per stream position, in order.
Example 1
Input
2 cd f abcd
Expected
NNNY
Explanation
After a, b, c none of the read-so-far strings ends with cd or f, giving N. After d, the string abcd ends with cd, giving Y. Output NNNY.
Example 2
Input
1 a aa
Expected
YY
Explanation
After the first a the stream ends with a -> Y; after the second a it still ends with a -> Y. Output YY.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →