Minimum Number of Operations to Make Array Continuous LeetCode solution in Java
1class Solution {2public int minOperations(int[] nums) {3TreeSet<Integer> set = new TreeSet<>();4int threshold = nums.length - 1;5int max = 0;6Arrays.sort(nums);7for (int num : nums) {8while (!set.isEmpty() && num - set.first() > threshold) {9set.remove(set.first());10}11set.add(num);12max = Math.max(max, set.size());13}14return nums.length - max;15}16}