1984. Minimum Difference Between Highest and Lowest of K Scores
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 58% Topics: Array, Sliding Window, Sorting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogn)
# Space: O(1)
class Solution(object):
def minimumDifference(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
nums.sort()
return min(nums[i]-nums[i-k+1] for i in xrange(k-1, len(nums)))
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions