[Java] Sorting, O(NlogN) , O(1)
 # Intuition\nDescribe your first thoughts on how to solve this problem.  \n\n# Approach\n\nWe can sort the array and then compare every element at index i with
<!-- # Intuition\nDescribe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can sort the array and then compare every element at index i with the element at index **i+k-1**. Take the minimum difference of all such pairs.\n\n# Complexity\n<!-- - Time complexity: -->\nTime Complexity - **O(NlogN)**\nSpace Complexity - **O(1)**\n<!-- - Space complexity: -->\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minimumDifference(int[] nums, int k) {\n        Arrays.sort(nums);\n        int res = Integer.MAX_VALUE;\n        for(int i=0; i<nums.length; i++){\n            if(i+k-1 >= nums.length) break;\n            res = Math.min(res, nums[i+k-1] - nums[i]);\n        }\n        return res;\n    }\n}\n```
['Java']