Minimum Difference Between Largest and Smallest Value in Three Moves LeetCode solution in Java
1class Solution {2public int minDifference(int[] nums) {3// sort the nums4// to gain the mini difference5// we want to remove the three smallest or biggest6// 0 - 37// 1 - 28// 2 - 19// 3 - 010if (nums.length <= 4) {11return 0;12}1314Arrays.sort(nums);1516int left = 0, right = 3;1718int res = Integer.MAX_VALUE;19while (left <= 3) {20int mini = nums[left];21int max = nums[nums.length - right - 1];22res = Math.min(res, max - mini);2324left++;25right--;26}2728return res;29}30}