TomoLink
CompaniesMetaData Structures & AlgorithmsStream of Characters
DSA
HardArray

Stream of Characters

arraystringdesign

Problem Statement

Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words .

For example, if words = ["abc", "xyz"] and the stream added the four characters (one by one) 'a' , 'x' , 'y' , and 'z' , your algorithm should detect that the suffix "xyz" of the characters "axyz" matches "xyz" from words .

Implement the StreamChecker class:

StreamChecker(String[] words) Initializes the object with the strings array words .

boolean query(char letter) Accepts a new character from the stream and returns true if any non-empty suffix from the stream forms a word that is in words .

Examples

Example 1
Input:
Output:

Constraints

1 <= words.length <= 2000
1 <= words[i].length <= 200
words[i] consists of lowercase English letters.
letter is a lowercase English letter.
At most 4 * 10 ^4 calls will be made to query.
😤
Hard
Difficulty
Topic Info
ModuleDSA
CategoryArray
Sub-topicString
Tags
arraystringdesigntriedata stream
Navigation
Stream of Characters [Hard] | Meta Dsa | TomoLink