Maintain a Live Seller Performance Leaderboard With Score Resets

Last updated: November 29, 2026

Quick Overview

Design a leaderboard with `add_score(seller_id, delta)`, `top(k)` returning the sum of the k highest totals, and `reset(seller_id)` that sets a seller's total back to zero.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Design a leaderboard with `add_score(seller_id, delta)`, `top(k)` returning the sum of the k highest totals, and `reset(seller_id)` that sets a seller's total back to zero.

A technical-screen design-a-structure question in Amazon's style, framed around ranking marketplace sellers by a rolling performance score. The interviewer expects you to compare a heap per query with a sorted structure, and to justify the choice from the call mix.

What the Interviewer Expects
  • Keeps a hash map from seller to current total
  • Offers heapq.nlargest per top call and states its cost
  • Offers a sorted container for O(log n) updates and O(k) top
  • Handles reset as removal
  • Discusses ties and the read and write ratio
Key Topics to Cover
design a data structure
heaps
sorted containers
hash maps
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 return the seller ids, not just the sum, with ties broken by id?
  • How would you scale to 100 million sellers across machines?
  • How would you support rank(seller_id)?
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

Scores are integers, deltas may be positive. top(k) returns the sum of the k largest current totals (k at most the number of sellers with scores). reset removes a seller; a later add_score start...

High-Level Design

Always keep total: seller -> score. Then choose how to answer top:

  • Heap per query: heapq.nlargest(k, totals) costs O(nlog⁡k)O(n \log k) per call. Updates are O(1)O(1). Best when top is rare.
  • *...

Submit Your Answer
Markdown supported