Live Show Leaderboard Of Top Spenders With Refunds

Last updated: November 29, 2026

Quick Overview

Design a structure for a live show that records purchase amounts per buyer (including negative deltas for refunds or cancellations) and returns the top k buyers by current total spend at any moment.

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

0

0

0 solved


Design a structure for a live show that records purchase amounts per buyer (including negative deltas for refunds or cancellations) and returns the top k buyers by current total spend at any moment.

Whatnot shows often highlight top buyers to reward loyal bidders, and totals change when an order is cancelled or refunded. The interviewer wants to see a heap with lazy deletion and an honest discussion of when stale entries pile up.

What the Interviewer Expects
  • Keep an authoritative map of buyer to total
  • Push a new heap entry on every update instead of searching the heap
  • Skip stale entries when reading the top k
  • Restore popped valid entries so later queries still work
  • Bound heap growth with a periodic rebuild
Key Topics to Cover
heaps
lazy deletion
design a data structure
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 make top k O(k) if it is queried far more often than it is updated?
  • How would you shard this across many concurrent shows?
  • How do you break ties between equal spenders in a way buyers see as fair?
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

Operations: record(user, delta) adds a possibly negative amount; top(k) returns up to k (user, total) pairs with the largest positive totals, highest first, ties by user id. Buyers whose total d...

High-Level Design

A dictionary holds the true total for each buyer. A max-heap (stored as negated totals in Python's min-heap) holds candidate entries. Every update pushes a fresh (-total, user); old entries for that...


Submit Your Answer
Markdown supported

Related Questions