Track the Kth Highest Score in a Live Xbox Leaderboard

Last updated: November 29, 2026

Quick Overview

Scores for an Xbox tournament arrive one at a time. Design a class that, after each new score, returns the k-th highest score seen so far.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Scores for an Xbox tournament arrive one at a time. Design a class that, after each new score, returns the k-th highest score seen so far.

A short heap question used in Microsoft phone screens. The key insight the interviewer wants is that a min-heap of size k keeps the answer at its top, rather than sorting all scores each time.

What the Interviewer Expects
  • Keep a min-heap of the k largest scores
  • Push while the heap has fewer than k entries
  • Replace the top only when a new score beats it
  • Return None or a sentinel until k scores exist
  • State O(log k) per add and O(k) memory
Key Topics to Cover
heaps
top-k
streaming
Xbox scenario
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
  • Support removing a score when a match result is overturned.
  • Return the top k scores in order at any time.
  • Scores arrive across many servers. How do you combine per-server answers?
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
  • KthHighestScore(k, scores) initializes with optional seed scores.
  • add(score) returns the k-th highest so far, or None if fewer than k scores.
  • Duplicates count separately....
High-Level Design

Sorting on every add is O(n log n) each time. A min-heap of size k holds exactly the k largest values seen; its smallest element is the k-th largest overall. When a new score arrives and the heap is f...


Submit Your Answer
Markdown supported