First Unique Event in a Stream
Updated
Problem statement
You receive a stream of string events in order. After processing each event, report the earliest event value that has appeared exactly once in the entire prefix processed so far.
If the current prefix has no event value with frequency one, report the empty string for that position. Return one answer for every processed event.
Function
firstUniqueAfterEachEvent(events: String[]) → String[]Examples
Example 1
events = ["a","b","a","c"]return = ["a","a","b","b"]After the third event, a is repeated, so b becomes the earliest value seen exactly once. Adding c does not change that earliest unique value.
Example 2
events = ["x","x","y","y"]return = ["x","","y",""]The second and fourth prefixes contain no value with frequency one, so their answers are empty strings.
Example 3
events = []return = []An empty stream produces no prefix answers.
Constraints
0 <= events.length <= 2000001 <= events[i].length <= 30- Each event contains lowercase English letters.
More Google Phone Screen questions
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
- Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Incident MonitorStripe · OAStripe interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- String Interpolation with a Missing-Value ModeMongoDB · PHONE SCREENMongoDB interview questions
- Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- First Unique Character in a StreamAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Fixed-Order Task Run Time With CooldownWaymo · PHONE SCREENWaymo interview questions
- Character Counts with Retried Remote WorkersCoalition · PHONE SCREEN