Top K Active Users

Asked atHubSpot
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Define activity and the time window.
  2. 02Aggregate one count per user.
  3. 03Use a size-k min-heap or sort counts.
  4. 04Apply the required tie-breaker before returning results.

Reference answer

Then expect these follow-ups

  • How would you maintain this over a sliding day window?

    Tests: streaming

  • What tie-breaker makes the result deterministic?

    Tests: product semantics

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question