
In this Uber SDE2 level VO round, the coding/design question was conceptually simple, but it strongly tested state modeling under continuous updates.
The service needed to support:
postCustomerVisit(customerId)to record a visitgetFirstOneTimeVisitor()to return the earliest customer who has visited exactly once so far
If none exists, return None / null.
What This Question Is Really Testing
It combines two constraints:
- dynamic updates: visits keep arriving
- order preservation: you need the first valid one-time visitor, not any valid one
Many candidates struggle with deleting no-longer-valid users from the middle of an order structure.
Stable Modeling Approach
Use two structures:
HashMapfor visit counts percustomerIdQueuefor first-seen order
Update Path
On postCustomerVisit(customerId):
- Increase the count
- If this is the first visit, append to queue
Query Path
On getFirstOneTimeVisitor():
- Check whether the queue front still has count 1
- If not, pop it as stale
- Repeat until front is valid or queue is empty
- Return front if valid, otherwise
None
Why Lazy Cleanup Matters
The queue can contain stale users: users who were first-time when inserted, but later revisited.
That is intentional. Instead of deleting from the middle on every update, clean stale entries lazily from the front during query. It keeps the design simple and performs well in streaming-like workloads.
Common Follow-Ups in SDE2 Interviews
1) Complexity discussion
postCustomerVisit: amortized O(1)getFirstOneTimeVisitor: amortized O(1)
Each user is popped at most once.
2) Concurrency considerations
At SDE2 level, interviewers often ask about consistency:
- single-node: protect map + queue with synchronization
- distributed: shard by
customerIdand define deterministic ordering policy
3) Memory growth handling
For long-running services, historical IDs grow:
- apply TTL or sliding windows
- keep only recent active period in memory
- offload cold data to persistent storage
3 High-Frequency Uber SDE2 BQ Prompts
- Tell me about a time you realized the team was heading in the wrong direction. How did you course-correct?
- Tell me about a conflict with PM or a partner team on prioritization. How did you balance speed and engineering quality?
- Tell me about a production incident you handled. How did you triage, communicate, and prevent recurrence?
These BQs mainly test ownership depth at SDE2 level: not just task completion, but responsibility for outcomes and long-term reliability.
Prep Advice
For this category of problem, practice in this order:
- define state clearly
- explain update and query paths
- justify complexity and stale-entry handling
In interviews, this explanation order often matters as much as implementation.
Need real interview questions? Contact WeChat Coding0201: Get Questions.
Contact
Email: [email protected]
Telegram: @OAVOProxy