You're given an integer array nums and have the power to transform it strategically. In each move, you can change any element to any value you want - there are no restrictions!
Your mission is to minimize the difference between the largest and smallest values in the array after making at most 3 moves.
Key insight: Since you can change elements to any value, the optimal strategy is to either remove the largest elements or the smallest elements (or a combination) to minimize the range.
Input: An integer array nums
Output: The minimum possible difference between max and min values after at most 3 moves
Example: For [5,3,2,4], you can change 5 to 3, making the array [3,3,2,4]. The difference becomes 4-2=2.
Input & Output
Constraints
- 1 โค nums.length โค 105
- -109 โค nums[i] โค 109
- You have exactly 3 moves maximum
- Each move allows changing any element to any value