Stream of Characters

Hard
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Stream of Characters

Approach

Build trie over reversed words. Append new letters to stream and scan all suffixes from end against trie in O(maxWordLen) per query.

Complexity Analysis

Time
O(M)
Space
O(total characters)

Pattern

Reverse Trie for Streaming Prefix/Suffix Match

Why It Works

Any matching word suffix appears as a reversed prefix from the newest stream characters, so checking backwards in reverse-trie detects all endings.

Updated Feb 2026