Java solution using sliding window.
Intuition\n Describe your first thoughts on how to solve this problem. \nIf we sort the array then the the min difference occurs at the neighbours\n\n# Approach
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we sort the array then the the min difference occurs at the neighbours\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe sork the array and create a sliding window of size k.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n * logn) --> Sorting\n    O(n) --> Sliding\n    O(n * logn) --> Total Time Complexity\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1) -- No extra memory\n\n# Code\n```\nclass Solution {\n    public int minimumDifference(int[] nums, int k) {\n        //This is a sliding window problem, The intution is we want the min possible difference\n        // So if we sort the array then for the minimum we need to just check the neighbours so used sorting\n\n        // Edge case\n        if(k == 1){\n            return 0;\n        }\n\n        Arrays.sort(nums);\n        int min = Integer.MAX_VALUE;\n        int i = 0;\n        int j = k-1;\n        while(j < nums.length){\n            min = Math.min(min, nums[j] - nums[i]); //Finding the min\n            i++;\n            j++;\n        }\n        return min;\n    }\n}\n```
['Java']