Leetcode 2112 Solution
This article provides solution to leetcode question 2112 (minimum-difference-between-highest-and-lowest-of-k-scores)
Access this page by simply typing in "lcs 2112" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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