949. Stream of Characters (Aho-Corasick Lite)

HardTreesTrieStringStreaming

Given a dictionary of words and a stream of characters, after each character report whether some word from the dictionary is a suffix of the characters seen so far. Return the boolean answers in order as an array. The input is JSON {words, stream}.

Input: JSON {words, stream}.

Output: Array — a boolean per streamed character.

Examples

Example 1
Input: {"words":["cd","f","kl"],"stream":"abcdefghijkl"}
Output: [false,false,false,true,false,true,false,false,false,false,false,true]
Explanation: Matches after 'd', 'f', and 'l'.
Example 2
Input: {"words":["a"],"stream":"aa"}
Output: [true,true]
Explanation: Each 'a' matches.
Example 3
Input: {"words":["xyz"],"stream":"abc"}
Output: [false,false,false]
Explanation: No matches.

Constraints

Asked by

GoogleMetaAmazon
Solve this problem in the editor →