Loading...
Loading...
Loading...
A spell checker stores n words. For each of q queries, print YES if the query is exactly one of the stored words and NO otherwise. A prefix of a stored word is not a match.
Example 1
Input
4 3 car cart cat dog car ca cats
Output
YES NO NO
ca is a prefix only, and cats is not stored.
Example 2
Input
1 1 a a
Output
YES
Try the problem first. Open one hint at a time.
Build a trie and mark the last node of every stored word.
A query is a match only if its walk succeeds and the last node is marked.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor