First Non-Repeating Character in a Stream
Problem statement
You receive the lowercase characters of a stream one at a time. After each new character, report the earliest character in the stream prefix whose frequency is exactly one.
If the current prefix has no non-repeating character, report the empty string for that step.
Given stream, return one result for every prefix in arrival order.
Function
firstNonRepeatingAfterEachInput(stream: String) → String[]Examples
Example 1
stream = "google"return = ["g","g","g","","l","l"]After the second g, o is still unique; after the second o, no unique character remains until l arrives.
Example 2
stream = "aabc"return = ["a","","b","b"]The second a removes the only candidate. Then b becomes and remains the earliest unique character.
Example 3
stream = "abc"return = ["a","a","a"]The first character never repeats, so it stays at the front for every prefix.
Constraints
1 <= stream.length <= 100000.streamcontains only lowercase English letters.