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.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.
scores=[15, 40, 15], k=2 → 0
The two entrants who both scored 15 give a gap of 0.
scores=[33], k=1 → 0
A group of one person has a gap of 0.
k ≤ scores.length ≤ 1000scores[i] ≤ 10⁵scores=[70, 52, 88, 61, 74], k=3
13
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.