Minimum Difference Between Largest and Smallest Value in Three Moves

You are given an integer array nums.

In one move, you can choose one element of nums and change it to any value.

Return the minimum difference between the largest and smallest value of nums after performing at most three moves.

Example 1
Inputnums = [5,3,2,4]
Output0
After changing 2, 4, and 5 to 3, all values become 3, so the difference between the minimum and maximum is 0.
Example 2
Inputnums = [1,5,0,10,14]
Output1
After three moves the difference can be reduced to 1, and it can be shown that there is no way to make the difference 0 in 3 moves.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate