Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For the difference between the highest and lowest element to be minimized, the k chosen scores need to be as close to each other as possible.
What if the array was sorted?
After sorting the scores, any contiguous k scores are as close to each other as possible.
Apply a sliding window solution to iterate over each contiguous k scores, and find the minimum of the differences of all windows.