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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

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
heaps
top-k
hash map counting
heavy hitters
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 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 Problems
Sample 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 O(mlog⁡m)O(m \log m); a heap of size k costs O(mlog⁡k)O(m \log k). The ordering ke...


Submit Your Answer
Markdown supported