Top K Most Requested Pickup Spots From a Request Log
Last updated: November 29, 2026
Quick Overview
Given a list of pickup location IDs from ride requests and an integer k, return the k most frequent locations, ordered by count descending and then by location ID ascending for ties.
Uber
November 29, 20260
0
0 solved
Given a list of pickup location IDs from ride requests and an integer k, return the k most frequent locations, ordered by count descending and then by location ID ascending for ties.
A frequent Uber phone screen question framed around airport and stadium pickup hotspots. Interviewers check counting plus heap selection, deterministic tie-breaking, and whether you can discuss the streaming version.
What the Interviewer Expects
- Counts frequencies with a hash map
- Selects top k with a size-k heap or nlargest rather than a full sort when k is small
- Applies the tie-break rule exactly as specified
- Mentions bucket sort for O(n)
- Discusses approximate counting for an unbounded stream
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you keep the top k updated as requests stream in?
- What if the log is too large for one machine?
- How would you use a Count-Min Sketch with a heap for heavy hitters?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list of location ID strings,
1 <= k <= distinct locations. - Output: k IDs, highest count first, ties broken by ID ascending.
- The log may hold millions of entries but far fewer distinct l...
High-Level Design
First count occurrences with a dictionary in one pass. Then pick the top k of the m distinct locations. Sorting all of them costs ; a heap of size k costs . The ordering ke...