|
| 1 | +<h2><a href="https://leetcode.com/problems/minimum-number-of-operations-to-make-array-continuous">2119. Minimum Number of Operations to Make Array Continuous</a></h2><h3>Hard</h3><hr><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> |
| 2 | + |
| 3 | +<p><code>nums</code> is considered <strong>continuous</strong> if both of the following conditions are fulfilled:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>All elements in <code>nums</code> are <strong>unique</strong>.</li> |
| 7 | + <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> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<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> |
| 11 | + |
| 12 | +<p>Return <em>the <strong>minimum</strong> number of operations to make </em><code>nums</code><em> </em><strong><em>continuous</em></strong>.</p> |
| 13 | + |
| 14 | +<p> </p> |
| 15 | +<p><strong class="example">Example 1:</strong></p> |
| 16 | + |
| 17 | +<pre> |
| 18 | +<strong>Input:</strong> nums = [4,2,5,3] |
| 19 | +<strong>Output:</strong> 0 |
| 20 | +<strong>Explanation:</strong> nums is already continuous. |
| 21 | +</pre> |
| 22 | + |
| 23 | +<p><strong class="example">Example 2:</strong></p> |
| 24 | + |
| 25 | +<pre> |
| 26 | +<strong>Input:</strong> nums = [1,2,3,5,6] |
| 27 | +<strong>Output:</strong> 1 |
| 28 | +<strong>Explanation:</strong> One possible solution is to change the last element to 4. |
| 29 | +The resulting array is [1,2,3,5,4], which is continuous. |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p><strong class="example">Example 3:</strong></p> |
| 33 | + |
| 34 | +<pre> |
| 35 | +<strong>Input:</strong> nums = [1,10,100,1000] |
| 36 | +<strong>Output:</strong> 3 |
| 37 | +<strong>Explanation:</strong> One possible solution is to: |
| 38 | +- Change the second element to 2. |
| 39 | +- Change the third element to 3. |
| 40 | +- Change the fourth element to 4. |
| 41 | +The resulting array is [1,2,3,4], which is continuous. |
| 42 | +</pre> |
| 43 | + |
| 44 | +<p> </p> |
| 45 | +<p><strong>Constraints:</strong></p> |
| 46 | + |
| 47 | +<ul> |
| 48 | + <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> |
| 49 | + <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> |
| 50 | +</ul> |
0 commit comments