Java solution | nLogn & O(1) | 5ms & Faster than 81%
\nclass Solution {\n    public int minimumDifference(int[] nums, int k) {\n        if(nums.length==1) return 0;\n        Arrays.sort(nums);\n        int n= k-1;
```\nclass Solution {\n    public int minimumDifference(int[] nums, int k) {\n        if(nums.length==1) return 0;\n        Arrays.sort(nums);\n        int n= k-1;\n        int minDiff = Math.abs(nums[0]-nums[n]);\n        for(int i=1; i<nums.length-n; i++) {\n           int min = Math.abs(nums[i]-nums[i+n]);\n           minDiff = Math.min(minDiff, min); \n        }\n        return minDiff;\n    }\n}\n```
[]