Minimum Difference Between Highest and Lowest of K Scores
You are given a 0-indexed integer array nums, where nums[i] represents the score of the i^th student. You are also given an integer k.
Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k scores is minimized.
Return the minimum possible difference.
Example 1
Input
nums = [90], k = 1Output
0There is one way to pick one score, so the highest and lowest score are both 90 and the difference is 0.
Example 2
Input
nums = [9,4,1,7], k = 2Output
2Among all ways to pick two scores, choosing 9 and 7 gives the minimum possible difference of 2.
Constraints
- 1 <= k <= nums.length <= 1000
- 0 <= nums[i] <= 10^5