First Rider ID Seen Exactly Once in a Live Request Stream

Last updated: November 29, 2026

Quick Overview

Ride requests arrive one at a time as rider IDs. Support add(rider_id) and first_unique(), which returns the earliest-arriving rider ID that has so far appeared exactly once, or None, with O(1) time per operation.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Ride requests arrive one at a time as rider IDs. Support add(rider_id) and first_unique(), which returns the earliest-arriving rider ID that has so far appeared exactly once, or None, with O(1) time per operation.

A streaming data structure question in the style of Uber's Online Assessment, motivated by spotting one-off riders in a burst of duplicate requests. The grader checks that you combine a count map with an insertion-ordered structure and avoid rescanning the stream.

What the Interviewer Expects
  • Tracks counts per rider ID
  • Keeps unique IDs in arrival order
  • Removes an ID from the ordered set when it repeats
  • Achieves O(1) per add and query
  • Explains why a plain queue needs lazy cleanup
Key Topics to Cover
Hash maps
Ordered dictionary
Streaming
Design
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you limit memory if the stream is unbounded?
  • How would you return the first ID seen exactly once in the last 10 minutes?
  • How would you shard this across machines?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

API: add(rider_id) and first_unique(). IDs are hashable strings. Both operations must be O(1)O(1), so scanning a list for the first unique ID on each query is not acceptable....

High-Level Design

Keep counts, a dict of how many times each ID appeared, and uniques, an insertion-ordered dict holding exactly the IDs with count 1, in arrival order. On add, increment the count; if it becomes ...


Submit Your Answer
Markdown supported