Python 2 line + CPP Soln With  Explanation
\nThis Q is asking what is the minimum difference between nums[i] and nums[i+(k-1)] for all.\n        k-1 beacuse Total K Values = from nums[i] to nums[i+k-1]\n
```\nThis Q is asking what is the minimum difference between nums[i] and nums[i+(k-1)] for all.\n        k-1 beacuse Total K Values = from nums[i] to nums[i+k-1]\n                                          -------    -----------\n                                          1 value     k-1 values\n                                          = 1 + k-1\n                                          = k values\n```\n```\nnums = [7, 1, 9, 3] , k = 2\n\nfor the value nums[1] = 1, ONLY 3 - 1 = 2 WHICH IS THE MINIMUM AMONG 7 - 1 = 6 and 9 - 1 = 8.\nBecause the closest MINIMUM value of 1 is 3. 7 and 9 are far away from 1.\n" So the far they are, the more difference it is. " \n```\n```\nSo sort and compare the minimum for every i by creating a "sliding window" at first\nlike :    minDiff = nums[k-1]-nums[0]  \nNow move this window till the i for which k exist means for nums[i] there exists a nums[k]\n```\n```Python []\nclass Solution:\n    def minimumDifference(self, nums: List[int], k: int) -> int:\n        nums.sort()\n        return min( nums[i+k-1]-nums[i] for i in range(len(nums)-k+1) )\n```\n```CPP  []\nclass Solution \n{\npublic:\n    int minimumDifference(vector<int>& nums, int k) \n    {\n        sort(nums.begin(),nums.end());\n        int minDiff = nums[k-1]-nums[0], n = nums.size()-k+1;\n        for(int i=1;i<n;i++)\n            minDiff = min(minDiff,nums[i+k-1]-nums[i]);\n        return minDiff;\n    }\n};\n```\n```\nTime  complexity : O(nlogn)\nSpace complexity : O(1)\n```
['C++', 'Python3']