|
| 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 | + */ |
| 43 | +pub 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 | + |
| 50 | +impl Solution { |
| 51 | + pub fn min_operations(nums: Vec<i32>) -> i32 { |
| 52 | + 0 |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// submission codes end |
| 57 | + |
| 58 | +#[cfg(test)] |
| 59 | +mod tests { |
| 60 | + use super::*; |
| 61 | + |
| 62 | + #[test] |
| 63 | + #[ignore] |
| 64 | + fn test_2009_example_1() { |
| 65 | + let nums = vec![4, 2, 5, 3]; |
| 66 | + |
| 67 | + let result = 0; |
| 68 | + |
| 69 | + assert_eq!(Solution::min_operations(nums), result); |
| 70 | + } |
| 71 | + |
| 72 | + #[test] |
| 73 | + #[ignore] |
| 74 | + fn test_2009_example_2() { |
| 75 | + let nums = vec![1, 2, 3, 5, 6]; |
| 76 | + |
| 77 | + let result = 1; |
| 78 | + |
| 79 | + assert_eq!(Solution::min_operations(nums), result); |
| 80 | + } |
| 81 | + |
| 82 | + #[test] |
| 83 | + #[ignore] |
| 84 | + fn test_2009_example_3() { |
| 85 | + let nums = vec![1, 10, 100, 1000]; |
| 86 | + |
| 87 | + let result = 3; |
| 88 | + |
| 89 | + assert_eq!(Solution::min_operations(nums), result); |
| 90 | + } |
| 91 | +} |
0 commit comments