Trains the technique from
LeetCode 1984Minimum Difference Between Highest and Lowest of K ScoresThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A rack holds the readings readings. Choose exactly k of them, and let the spread of a choice be its largest reading less its smallest.
Return the smallest spread any choice of k readings can manage.
Example 1
In order the readings run 1, 5, 6, 14, 15. The three standing closest together are 1, 5 and 6, spreading 5.
Example 2
Every reading is the same, so any two of them spread nothing at all.
Example 3
Both readings have to be taken, so the spread is the gap between them.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def minimum_difference(readings: list[int], k: int) -> int:public int minimumDifference(int[] readings, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.