Description

Design a StreamChecker that checks if the last k characters queried spell any word from a dictionary.

Examples

Input:words = ["cd","f","kl"], queries = [a,b,c,d,e,f]
Output:[false,false,false,true,false,true]
Explanation:

'cd' and 'f' found.

Input:words = ["abc","xyz"], queries = [x,y,z,a,b,c]
Output:[false,false,true,false,false,true]
Explanation:

After querying 'x','y','z' the last 3 characters form 'xyz', matching a dictionary word. After 'x','y','z','a','b','c' the last 3 characters 'abc' also match.

Input:words = ["hello","hi","world"], queries = [h,i,w,o,r,l,d,h,e,l,l,o]
Output:[false,true,false,false,false,false,true,false,false,false,false,true]
Explanation:

After querying 'h','i' the last 2 characters form 'hi'. After 'w','o','r','l','d' the last 5 characters form 'world'. After the full sequence ending with 'h','e','l','l','o' the last 5 characters form 'hello'.

Constraints

  • 1 ≤ words.length ≤ 2000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!