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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

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
Sorting
Fixed Window
Two Pointers
Greedy Argument
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
  • 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 Problems
Sample Answer
Requirements
  • Input: list ratings of integers, integer k with 1 <= k <= n.
  • Output: the minimum value of max(group) - min(group) over all groups of k players....
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...


Submit Your Answer
Markdown supported