First Non-Repeating Character in a Stream
Read lowercase English letters from left to right. After each consumed character, append the earliest character in that prefix whose frequency is exactly one,…
Read lowercase English letters from left to right. After each consumed character, append the earliest character in that prefix whose frequency is exactly one, or # if none exists. Return all prefix answers concatenated into one string. First means stream occurrence order, not alphabetic order. This is not a request for one final index or character. Implement first_non_repeating_stream in Python or firstNonRepeatingStream in the other languages.
- 1 <= stream.length <= 10000. - Every character is lowercase ASCII a through z. - Return exactly stream.length characters, each a lowercase letter or #. - Empty, uppercase, Unicode and nonletter inputs are outside the contract; no coercion or case-folding. - Preset traces contain at most 12 characters; coding retains the complete bounds.
Example 1: input stream = "aabc"; output "a#bb". a is unique first, then repeated; b becomes first and stays first when c arrives.
Example 2: input stream = "aaa"; output "a##". The first prefix has one unique a; every later prefix has none.
Example 3: input stream = "ba"; output "bb". b arrived before a, so alphabetic order is irrelevant.
Category: Queues. Topic: queue. Difficulty: Medium. Patterns: string-processing.