Smallest Score Spread When Picking K Players for a Leaderboard
Last updated: November 29, 2026
Quick Overview
Given an array of player skill ratings and an integer k, choose k players so that the difference between the highest and lowest chosen rating is as small as possible, and return that difference.
0
0
0 solved
Given an array of player skill ratings and an integer k, choose k players so that the difference between the highest and lowest chosen rating is as small as possible, and return that difference.
A Google online-assessment style question framed around building balanced matchmaking lobbies for a game on Google Play. The interviewer checks that the candidate sees that an optimal group is always contiguous after sorting, which turns it into a fixed window scan.
What the Interviewer Expects
- Sorts the ratings first
- Argues that an optimal group is contiguous in sorted order
- Scans windows of size k comparing ends
- Handles k equal to 1
- States O(n log n) time
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
- What if you must split all players into lobbies of size k minimizing the maximum spread?
- How would you handle ratings arriving in a stream?
- What if the cost is the variance of the group instead of the range?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list
ratingsof integers, integerkwith1 <= k <= n. - Output: the minimum value of
max(group) - min(group)over all groups ofkplayers....
High-Level Design
Sort the ratings. Claim: some optimal group is a contiguous block of the sorted array. Proof sketch: take any optimal group with minimum lo and maximum hi. Every rating between them in sorted orde...