You are given a 0-indexed integer array nums, where nums[i] represents the score of the ith 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.

&nbsp;
Example 1:

Input: nums = [90], k = 1
Output: 0
Explanation: There is one way to pick score(s) of one student:
- [90]. The difference between the highest and lowest score is 90 - 90 = 0.
The minimum possible difference is 0.


Example 2:

Input: nums = [9,4,1,7], k = 2
Output: 2
Explanation: There are six ways to pick score(s) of two students:
- [9,4,1,7]. The difference between the highest and lowest score is 9 - 4 = 5.
- [9,4,1,7]. The difference between the highest and lowest score is 9 - 1 = 8.
- [9,4,1,7]. The difference between the highest and lowest score is 9 - 7 = 2.
- [9,4,1,7]. The difference between the highest and lowest score is 4 - 1 = 3.
- [9,4,1,7]. The difference between the highest and lowest score is 7 - 4 = 3.
- [9,4,1,7]. The difference between the highest and lowest score is 7 - 1 = 6.
The minimum possible difference is 2.

&nbsp;
Constraints:


	1 &lt;= k &lt;= nums.length &lt;= 1000
	0 &lt;= nums[i] &lt;= 105


class Solution:
    def minimumDifference(self, nums: List[int], k: int) -> int:
        nums.sort()
        cur = float('inf')
        for i in range(len(nums)-k+1):
            cur = min(cur, nums[i+k-1]-nums[i])
class Solution {
    public int minimumDifference(int[] nums, int k) {
        if(k == 1)return 0;
        int i = 0,j = k-1,res = Integer.MAX_VALUE;

        Arrays.sort(nums);
        while(j < nums.length){
            res = Math.min(res,nums[j] - nums[i]);
            j++;
            i++;
        }

        return res;
    }
}
class Solution {
public:
    int minimumDifference(vector<int>& nums, int k) {
        sort(nums.begin(), nums.end());
        int res = nums[k-1] - nums[0];
        for (int i = k; i < nums.size(); i++) res = min(res, nums[i] - nums[i-k+1]);
        return res;
    }
};
```/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var minimumDifference = function(nums, k) {
    nums.sort((a,b)=>a-b)
    let min=nums[0],max=nums[k-1],diff=max-min
    for(let i=k;i<nums.length;i++){
        diff=Math.min(diff,nums[i]-nums[i-k+1])
    }
    return diff
};``
Minimum Difference Between Highest and Lowest of K Scores