/*
* @lc app=leetcode.cn id=1984 lang=typescript
*
* [1984] 学生分数的最小差值
*/
// @lc code=start
function minimumDifference(nums: number[], k: number): number {}
// @lc code=end
function minimumDifference(nums: number[], k: number): number {
nums.sort((a, b) => a - b)
let res = Infinity
for (let i = 0, j = k - 1; j < nums.length; i++, j++) {
res = Math.min(res, nums[j] - nums[i])
}
return res
}
test.each([
{ input: { nums: [90], k: 1 }, output: 0 },
{ input: { nums: [9, 4, 1, 7], k: 2 }, output: 2 },
])('input: nums = $input.nums, k = $input.k', ({ input: { nums, k }, output }) => {
expect(minimumDifference(nums, k)).toEqual(output)
})