Input: nums =[1,4,7,8,5]Output: 3Explanation:
* Change `nums[0]` and `nums[1]` to be 6 so that `nums` becomes [6,6,7,8,5].* The low score is the minimum absolute difference:|6-6|=0.* The high score is the maximum absolute difference:|8-5|=3.* The sum of high and low score is3.
Input: nums =[1,4,3]Output: 0Explanation:
* Change `nums[1]` and `nums[2]` to 1 so that `nums` becomes [1,1,1].* The sum of maximum absolute difference and minimum absolute difference is0.
To minimize the score after changing two elements, we can change the two largest or two smallest elements to match others. The minimum score is the minimum among three options:
(nums[n-1] - nums[0]) + (nums[2] - nums[1])
But since low score is always 0 after changing two elements to be equal, the score is just the difference between the remaining max and min.
So, answer is min(nums[n-1]-nums[2], nums[n-3]-nums[0], nums[n-2]-nums[1]).