Minimize Range After Three Changes
Problem statement
You are given an integer array nums. You may change the value of at most three elements to any integers.
Return the minimum possible difference between the largest and smallest values after the changes.
Function
minimizeRange(nums: int[]) → intExamples
Example 1
nums = [5,3,2,4]return = 0Change three values to match the remaining value, so the range becomes 0.
Example 2
nums = [1,5,6,14,15]return = 1Keep 5 and 6 and change the other three elements.
Example 3
nums = [6,6,0,1,1,4,6]return = 2Changing 0, both 1s, or an equivalent set leaves values between 4 and 6.
Constraints
1 <= nums.length <= 100000-1000000000 <= nums[i] <= 1000000000