Java solution with detailed explanation
Intuition\nSince we can change the value of atmost 2 elements, we are left with three choices, I will explain why these three choices only.\n\nWe know the max s
# Intuition\nSince we can change the value of atmost 2 elements, we are left with three choices, I will explain why these three choices only.\n\nWe know the max score we can achieve is by subtracting the min element from the max element.\nNow we are given a condition that we can change atmost two values, and so we can reduce the min score to 0(always) by choosing any two numbers are setting them to same value, so the problem boils down to simply reduce the max score which is (arr[max_Index] - arr[min_Index])\n\nNow we have three choices:\n\nFirst: we decide to change the value of first two minimum elements of the array to the third one and then calculate the score.\n\nSecond: we decide to change the value of first two maxmium elements of the array to the third one and then calculate the score.\n\nThird: we decide to change the value of minimum element to 2nd minimum element and the value of first maximum element to 2nd maximum element and then we calculate score.\n\nThen we will return the min of all the three choices\n\nThe reason we did this was because we know that we need to minimize the maximum score, and the maimum score is nothing but the the difference between two extremes of the arrays, and by these three choices we tried to reduce this maximum difference.\n\nNow to find the required max and min values, we can also do this in linear-pass instead of sorting, but I\'ll leave that as an exercise for you.\n\nDo Upvote!\n\n# Code\n```\nclass Solution {\n    public int minimizeSum(int[] nums) {\n        Arrays.sort(nums);\n        int min = nums[nums.length-3] - nums[0];\n        min = Math.min(nums[nums.length-1] - nums[2], min);\n        min = Math.min(nums[nums.length-2] - nums[1], min);\n        \n        return min;\n        \n    }\n}\n```
['Java']