2009. Minimum Number of Operations to Make Array Continuous Hard
1/**
2 * [2009] Minimum Number of Operations to Make Array Continuous
3 *
4 * You are given an integer array nums. In one operation, you can replace any element in nums with any integer.
5 * nums is considered continuous if both of the following conditions are fulfilled:
6 *
7 * All elements in nums are unique.
8 * The difference between the maximum element and the minimum element in nums equals nums.length - 1.
9 *
10 * For example, nums = [4, 2, 5, 3] is continuous, but nums = [1, 2, 3, 5, 6] is not continuous.
11 * Return the minimum number of operations to make nums continuous.
12 *
13 * Example 1:
14 *
15 * Input: nums = [4,2,5,3]
16 * Output: 0
17 * Explanation: nums is already continuous.
18 *
19 * Example 2:
20 *
21 * Input: nums = [1,2,3,5,6]
22 * Output: 1
23 * Explanation: One possible solution is to change the last element to 4.
24 * The resulting array is [1,2,3,5,4], which is continuous.
25 *
26 * Example 3:
27 *
28 * Input: nums = [1,10,100,1000]
29 * Output: 3
30 * Explanation: One possible solution is to:
31 * - Change the second element to 2.
32 * - Change the third element to 3.
33 * - Change the fourth element to 4.
34 * The resulting array is [1,2,3,4], which is continuous.
35 *
36 *
37 * Constraints:
38 *
39 * 1 <= nums.length <= 10^5
40 * 1 <= nums[i] <= 10^9
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/minimum-number-of-operations-to-make-array-continuous/
46// discuss: https://leetcode.com/problems/minimum-number-of-operations-to-make-array-continuous/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn min_operations(nums: Vec<i32>) -> i32 {
52 0
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_2009() {
64 }
65}
66
Back
© 2025 bowen.ge All Rights Reserved.