Live Leaderboard of Top-Rated Drivers With Frequent Rating Updates

Last updated: November 29, 2026

Quick Overview

Maintain a leaderboard where update(driver, rating) sets a driver's current rating and top(k) returns the k drivers with the highest current rating, ties broken by driver ID ascending. Updates are far more frequent than queries.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Maintain a leaderboard where update(driver, rating) sets a driver's current rating and top(k) returns the k drivers with the highest current rating, ties broken by driver ID ascending. Updates are far more frequent than queries.

An Uber onsite question for marketplace and incentives teams, where driver quality scores change after every trip. Interviewers look for lazy deletion in a heap or an ordered structure, and an honest discussion of stale entries.

What the Interviewer Expects
  • Keeps the current rating per driver in a dict as the source of truth
  • Pushes (negative rating, id) into a heap on each update without removing the old entry
  • Skips stale entries during top(k) by checking against the dict
  • Restores popped valid entries after answering
  • Mentions compaction when stale entries grow too large
Key Topics to Cover
design a data structure
heap
lazy deletion
top-k
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 bound memory if one driver updates a million times?
  • Use a balanced BST or sorted list instead, and compare costs.
  • How would you build a per-city leaderboard over a sliding 7-day window?
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
  • update(driver, rating): set the current rating (new or existing driver).
  • top(k): up to k IDs by rating desc then ID asc, using current ratings only.
  • Updates dominate; queries are occasional....
High-Level Design

Store current[driver] and push (-rating, driver) into a min-heap on every update, leaving older entries in place. In top(k), pop from the heap. An entry is valid only if `current[driver] == rati...


Submit Your Answer
Markdown supported