<p>You are given an integer array <code>nums</code>. In one operation, you can replace <strong>any</strong> element in <code>nums</code> with <strong>any</strong> integer.</p>

<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p>

<ul>
	<li>All elements in <code>nums</code> are <strong>unique</strong>.</li>
	<li>The difference between the <strong>maximum</strong> element and the <strong>minimum</strong> element in <code>nums</code> equals <code>nums.length - 1</code>.</li>
</ul>

<p>For example, <code>nums = [4, 2, 5, 3]</code> is <strong>continuous</strong>, but <code>nums = [1, 2, 3, 5, 6]</code> is <strong>not continuous</strong>.</p>

<p>Return <em>the <strong>minimum</strong> number of operations to make </em><code>nums</code><em> </em><strong><em>continuous</em></strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,2,5,3]
<strong>Output:</strong> 0
<strong>Explanation:</strong>&nbsp;nums is already continuous.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,5,6]
<strong>Output:</strong> 1
<strong>Explanation:</strong>&nbsp;One possible solution is to change the last element to 4.
The resulting array is [1,2,3,5,4], which is continuous.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,10,100,1000]
<strong>Output:</strong> 3
<strong>Explanation:</strong>&nbsp;One possible solution is to:
- Change the second element to 2.
- Change the third element to 3.
- Change the fourth element to 4.
The resulting array is [1,2,3,4], which is continuous.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def minOperations(self, nums: List[int]) -> int:
        """
        This function calculates the minimum number of operations required to make the array continuous.
        The task is to find the smallest number of elements to remove such that the array becomes continuous,
        meaning that all the elements in the array form a sequence of consecutive numbers.

        Args:
        nums (List[int]): The input list of integers.

        Returns:
        int: The minimum number of operations (removals) required to make the array continuous.
        """
        # Store the original length of the input array
        original_length = len(nums)
        # Remove duplicates and sort the remaining elements, as we are interested in continuous sequences
        nums = sorted(set(nums))
        # Initialize the right pointer for the sliding window and the variable to store the result.
        # The result will store the minimum number of operations needed.
        right_pointer = 0
        min_operations_required = original_length

        # Iterate through the sorted array with the left pointer
        for left_pointer in range(len(nums)):
            # Expand the window by moving the right pointer to include elements less than nums[left_pointer] + original_length.
            while right_pointer < len(nums) and nums[right_pointer] < nums[left_pointer] + original_length:
                right_pointer += 1
            # Calculate the current window size (number of elements in the window)
            current_window_size = right_pointer - left_pointer
            # Calculate the number of elements outside the window, which need to be removed to make the array continuous.
            # Update the result with the minimum operations required.
            min_operations_required = min(min_operations_required, original_length - current_window_size)

        # Return the minimum number of operations required to make the array continuous.
        return min_operations_required

# time complexity: O(nlogn) where "n" is the length of the input list "nums" because we are sorting the list "nums" which takes O(nlogn) time.
# space complexity: O(n) where "n" is the length of the input list "nums" because we are storing the sorted list of "nums" in the list "nums".
598