Java | With Explanation
Let say arr : \n[2,3,1,9,8,6,4]\n\nAfter sort :\n[1,2,3,4,6,8,9]\n\nwe\'ll replace 3 max/min elements with the min/max respectively\nobviously to make the diff 
Let say arr : \n`[2,3,1,9,8,6,4]`\n\nAfter sort :\n`[1,2,3,4,6,8,9]`\n\nwe\'ll replace 3 max/min elements with the min/max respectively\nobviously to make the diff smaller.\n\n**case1** - [1,2,3,4,changed,changed,changed] => `res = Min(res,4-1) = 3`\n**case2** - [changed,2,3,4,5,changed,changed] => `res = Min(res,5-2) = 3`\n**case3** - [changed,changed,3,4,5,6,changed] => `res = Min(res,6-3) = 3`\n**case4** - [changed,changed,changed,4,5,6,7] => `res = Min(res,7-4) = 3`\n\n```\nclass Solution {\n    public int minDifference(int[] nums) {\n        int n = nums.length;\n        if(n <= 3) return 0;\n        Arrays.sort(nums);\n        int res = Integer.MAX_VALUE;\n        for(int i=0;i<=3;i++)\n            res = Math.min(res,nums[n-4+i]-nums[i]);\n        return res;\n    }\n}\n```
[]