2112. Minimum Difference Between Highest and Lowest of K Scores
My accepted Python solution to LeetCode problem 2112, Minimum Difference Between Highest and Lowest of K Scores, running in 7ms.
- Difficulty: Easy
- Python
- Runtime 7ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 7ms, memory 17.5MB, accepted 2025-12-30.
class Solution:
def minimumDifference(self, nums: List[int], k: int) -> int:
if k == 1:
return 0
nums.sort()
min_diff = float('inf')
for i in range(len(nums) - k + 1):
diff = nums[i + k - 1] - nums[i]
min_diff = min(min_diff, diff)
return min_diff