Kth Highest Bid Seen So Far in a Live Ad Auction Stream
Last updated: November 29, 2026
Quick Overview
Bids for an ad slot arrive one at a time. Build a class that, after each new bid, returns the kth highest bid seen so far.
0
0
0 solved
Bids for an ad slot arrive one at a time. Build a class that, after each new bid, returns the kth highest bid seen so far.
A common Google phone-screen opener dressed up as an Ads auction feed, where a reserve price is tied to the kth best bid. The interviewer wants a bounded min-heap instead of re-sorting, and a clear argument for why the heap root is the answer.
What the Interviewer Expects
- Keeps a min-heap capped at size k
- Explains why the root is the kth largest
- Handles fewer than k bids seen so far
- Gives O(log k) per add and O(k) memory
- Writes a small class with a clean interface
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 support deleting a retracted bid?
- What if k changes at runtime?
- How would you shard this across many auction servers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Constructor takes
kand an optional list of initial bids. add(bid)records a bid and returns the kth highest bid so far.- If fewer than k bids exist, return
None(agree on this with the int...
High-Level Design
Only the k largest bids matter. Keep them in a min-heap of size at most k: the smallest of the top k sits at the root, and that is exactly the kth highest overall. When a new bid arrives, push it; if ...