3507. Minimum Pair Removal to Sort Array I Easy
1/**
2 * [3507] Minimum Pair Removal to Sort Array I
3 *
4 * Given an array nums, you can perform the following operation any number of times:
5 *
6 * Select the adjacent pair with the minimum sum in nums. If multiple such pairs exist, choose the leftmost one.
7 * Replace the pair with their sum.
8 *
9 * Return the minimum number of operations needed to make the array non-decreasing.
10 * An array is said to be non-decreasing if each element is greater than or equal to its previous element (if it exists).
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [5,2,3,1]</span>
15 * Output: <span class="example-io">2</span>
16 * Explanation:
17 *
18 * The pair (3,1) has the minimum sum of 4. After replacement, nums = [5,2,4].
19 * The pair (2,4) has the minimum sum of 6. After replacement, nums = [5,6].
20 *
21 * The array nums became non-decreasing in two operations.
22 * </div>
23 * <strong class="example">Example 2:
24 * <div class="example-block">
25 * Input: <span class="example-io">nums = [1,2,2]</span>
26 * Output: <span class="example-io">0</span>
27 * Explanation:
28 * The array nums is already sorted.
29 * </div>
30 *
31 * Constraints:
32 *
33 * 1 <= nums.length <= 50
34 * -1000 <= nums[i] <= 1000
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/minimum-pair-removal-to-sort-array-i/
40// discuss: https://leetcode.com/problems/minimum-pair-removal-to-sort-array-i/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn minimum_pair_removal(nums: Vec<i32>) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_3507() {
58 }
59}
60Back
© 2026 bowen.ge All Rights Reserved.