Stream of Characters
Design a class StreamChecker that answers suffix questions over a growing character stream.
The constructor receives a list of dictionary words. Each call to query(letter) appends that single character to the stream and returns true when at least one dictionary word is a suffix of everything received so far, or false otherwise.
Only the newest character can complete a new match. A previous match does not force later answers: every call must test the suffixes that end at the character just appended. Dictionary words are distinct or repeated, and a single query may complete more than one word. The stream is cumulative for the lifetime of the object.
Examples
Input: []
Output: 0
Input: ["a"]
Output: 0
Hints
A word can end only at the newest character, so compare candidate words from the right end of the stream.
Reverse every dictionary word and insert it into a trie. Walking the stream backward from the newest character visits exactly the suffixes that can match.
Stop a query at the first terminal trie node. A missing edge proves no remaining suffix can match.
Related Problems
Stream of Characters
Design a class `StreamChecker` that answers suffix questions over a growing character stream.