Leetcode 2112 Solution

This article provides solution to leetcode question 2112 (minimum-difference-between-highest-and-lowest-of-k-scores)

https://leetcode.com/problems/minimum-difference-between-highest-and-lowest-of-k-scores

Solution

class Solution:
    def minimumDifference(self, nums: List[int], k: int) -> int:
        nums.sort()

        ans = sys.maxsize
        for i in range(k - 1, len(nums)):
            ans = min(ans, nums[i] - nums[i - k + 1])
        return ans