JAVA EASIEST SOLUTION
A = [1,5,6,13,14,15,16,17]\nn = 8\n\nCase 1: kill 3 biggest elements\n\nAll three biggest elements can be replaced with 14\n[1,5,6,13,14,15,16,17] -> [1,5,6,13,
A = [1,5,6,13,14,15,16,17]\nn = 8\n\nCase 1: kill 3 biggest elements\n\nAll three biggest elements can be replaced with 14\n[1,5,6,13,14,15,16,17] -> [1,5,6,13,14,14,14,14] == can be written as A[n-4] - A[0] == (14-1 = 13)\n\nCase 2: kill 2 biggest elements + 1 smallest elements\n\n[1,5,6,13,14,15,16,17] -> [5,5,6,13,14,15,15,15] == can be written as A[n-3] - A[1] == (15-5 = 10)\n\nCase 3: kill 1 biggest elements + 2 smallest elements\n\n[1,5,6,13,14,15,16,17] -> [6,6,6,13,14,15,16,16] == can be written as A[n-2] - A[2] == (16-6 = 10)\n\nCase 4: kill 3 smallest elements\n\n[1,5,6,13,14,15,16,17] -> [13,13,13,13,14,15,16,17] == can be written as A[n-1] - A[3] == (17-13 = 4)\n\nAnswer is minimum of all these cases!\n\n\nclass Solution {\n\n    public int minDifference(int[] nums) {\n        Arrays.sort(nums);\n        \n        int n=nums.length;\n        if(n<=4)\n            return 0;\n        \n        int res=Integer.MAX_VALUE;\n        for(int i=0;i<=3;i++)\n        {\n            res=Math.min(res,nums[n-4+i]-nums[i]);\n        }\n        return res;    \n    }\n}
['Sorting', 'Java']