First Non-Repeating Character in a Stream
MediumP2Coding
Gifts arrive one at a time, each identified by a lowercase letter, and join a queue. After each arrival, report the first gift in the queue (from the front) whose letter appears exactly once in the queue so far, or # if no gift is unique.
Given the arrival string s, return a string of the same length whose i-th character is the report after the i-th arrival.
Example 1
- Input
- s = "aabc"
- Output
- "a#bb"
- Why
- After "a": a. After "aa": none, #. After "aab": b. After "aabc": b is still first unique.
Example 2
- Input
- s = "abc"
- Output
- "aaa"
Example 3
- Input
- s = "z"
- Output
- "z"
Constraints
- 1 <= s.length <= 10^5
- s consists of lowercase English letters
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.