Ctrl K

Tightest Group of Scores

Easy
You are given an array scores, where scores[i] is the score of the i-th contestant, and an integer k. Pick exactly k contestants for a team so that the gap between the highest and the lowest score among them is as small as possible. Return that smallest gap.
Example 1
scores=[70, 52, 88, 61, 74], k=3 → 13

Take 61, 70 and 74: the gap between best and worst is 74 − 61 = 13, and no choice does better.

Example 2
scores=[15, 40, 15], k=2 → 0

The two entrants who both scored 15 give a gap of 0.

Example 3
scores=[33], k=1 → 0

A group of one person has a gap of 0.

Constraints
  • 1 ≤ k ≤ scores.length ≤ 1000
  • 0 ≤ scores[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValues One Apart EasyClose Readings Nearby HardNarrowest Range Touching Every List HardNearest k Values MediumBest View for a Turning Camera Hard
loading Python…
Input
scores=[70, 52, 88, 61, 74], k=3
Expected
13

Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.