You are given an integer array nums. In one move, you can choose one element of nums and change it by any value.

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

&nbsp;
Example 1:

Input: nums = [5,3,2,4]
Output: 0
Explanation: Change the array [5,3,2,4] to [2,2,2,2].
The difference between the maximum and minimum is 2-2 = 0.


Example 2:

Input: nums = [1,5,0,10,14]
Output: 1
Explanation: Change the array [1,5,0,10,14] to [1,1,0,1,1]. 
The difference between the maximum and minimum is 1-0 = 1.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	-109 &lt;= nums[i] &lt;= 109


class Solution:
    def minDifference(self, nums: List[int]) -> int:
        if len(nums) <= 3:
            return 0

        nums.sort()
        t1 = nums[-1] - nums[3]
        t2 = nums[-4] - nums[0]
        t3 = nums[-2] - nums[2]
        t4 = nums[-3] - nums[1]

        return min(t1,t2,t3,t4)
class Solution {
    public int minDifference(int[] nums) {
        // sort the nums
        // to gain the mini difference
        // we want to remove the three smallest or biggest 
        // 0 - 3
        // 1 - 2
        // 2 - 1
        // 3 - 0
        if(nums.length <= 4){
            return 0;
        }
        
        Arrays.sort(nums);
        
        int left = 0, right = 3;
        
        int res = Integer.MAX_VALUE;
        while(left <= 3){
            int mini = nums[left];
            int max = nums[nums.length - right - 1];
            res = Math.min(res, max - mini);
            
            left++;
            right--;
        }
        
        return res;
    }
}
class Solution {
public:
    int minDifference(vector<int>& nums) {

        int n =nums.size();

        sort( nums.begin(), nums.end());

        if( n<5){
            return 0;

        }
        else return min({nums[n-4]- nums[0],nums[n-3]- nums[1] ,nums[n-2]-nums[2], nums[n-1]-nums[3]});

    }
};
var minDifference = function(nums) {
    let len = nums.length;
    if (len < 5) return 0;

    nums.sort((a,b) => a-b)
    
    return Math.min(
        
    ( nums[len-1] - nums[3] ),  // 3 elements removed from start 0 from end
    ( nums[len-4] - nums[0] ),  // 3 elements removed from end 0 from start
    ( nums[len-2] - nums[2] ),  // 2 elements removed from start 1 from end
    ( nums[len-3] - nums[1] ),  // 2 elements removed from end 1 from start
   

)
    
    
    
      
};
Minimum Difference Between Largest and Smallest Value in Three Moves