Stream of Characters

Hard · Trie · about 30 minutes

Asked at Google, Amazon, Meta.

Design an algorithm that receives a stream of characters and checks whether a suffix of the stream is one of the given words.

  • StreamChecker(words) stores the words.
  • query(letter) appends letter to the stream and returns true if some suffix of the stream (including

the latest letter) is in words.

Related guides