nlogn
\n\n# Code\n\nclass Solution:\n    def minimumDifference(self, nums: List[int], k: int) -> int:\n        nums.sort() # we sort the element\n        l,r = 0,k-1\
\n\n# Code\n```\nclass Solution:\n    def minimumDifference(self, nums: List[int], k: int) -> int:\n        nums.sort() # we sort the element\n        l,r = 0,k-1\n        res = float("inf")\n\n        while r < len(nums):\n            res = min(res,nums[r]-nums[l])\n            l,r = l+1,r+1\n        return res\n\n# time  complexity -- O(Nlogn)\n```
['Python3']