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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
min-heap
top-k
streaming
heapq
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 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 Problems
Sample Answer
Requirements
  • Constructor takes k and an initial list of counts.
  • add(views) inserts one count and returns the kth largest so far.
  • Until at least k counts exist, return None (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:

  1. If the heap h...

Submit Your Answer
Markdown supported