Track the Kth Highest Reel View Count as Views Stream In
Last updated: November 29, 2026
Quick Overview
Reel view counts arrive one at a time. Build a class that, after each new count, returns the kth largest count seen so far (or None until k counts exist).
Meta
November 29, 20260
0
0 solved
Reel view counts arrive one at a time. Build a class that, after each new count, returns the kth largest count seen so far (or None until k counts exist).
A warm-up in Meta's coding phone screen, framed around ranking Reels for a creator dashboard. The interviewer wants to see that you reach for a size-k min-heap instead of re-sorting, and that you can state why its root is the answer.
What the Interviewer Expects
- Use a min-heap capped at size k
- Explain why the heap root is the kth largest
- Handle fewer than k values gracefully
- State O(log k) per add and O(k) memory
- Write clean, bug-free code quickly
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 removing a count when a Reel is deleted?
- What if k changes at runtime?
- How would you shard this across many creators' dashboards?
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 initial list of counts. add(views)inserts one count and returns the kth largest so far.- Until at least
kcounts exist, returnNone(clarify this with the inte...
High-Level Design
Keep only the k largest values seen in a min-heap. The smallest element of that set sits at the root, and it is by definition the kth largest overall. When a new value arrives:
- If the heap h...