2009. Minimum Number of Operations to Make Array Continuous
On This Page
class Solution:
def minOperations(self, nums: List[int]) -> int:
n = len(nums)
nums = sorted(set(nums))
res, j = n, 0
for i, v in enumerate(nums):
while j < len(nums) and nums[j] - v <= n - 1:
j += 1
res = min(res, n - (j - i))
return res