Stream of Characters
Master this topic with zero to advance depth.
Stream of Characters
Design a data structure that accepts a stream of characters and checks if any suffix of the characters queried so far is in a given list of words.
Examples
Level I: Brute Force Suffix Comparison
Intuition
Store all arrived characters in a list. For every query, iterate through all words in the dictionary and check if any word matches the current suffix of the character stream. O(N * L) per query.
Level III: Reverse Trie
Intuition
Since we need to match a suffix of the stream, it's efficient to store the dictionary words in a Trie in reversed order. As new characters arrive in the stream, we store them in a buffer (or current path). To check if any suffix matches, we traverse the reversed Trie starting from the last character received.
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.