2826. Sorting Three Groups Medium
1/**
2 * [2826] Sorting Three Groups
3 *
4 * You are given an integer array nums. Each element in nums is 1, 2 or 3. In each operation, you can remove an element from nums. Return the minimum number of operations to make nums non-decreasing.
5 *
6 * <strong class="example">Example 1:
7 * <div class="example-block">
8 * Input: <span class="example-io">nums = [2,1,3,2,1]</span>
9 * Output: <span class="example-io">3</span>
10 * Explanation:
11 * One of the optimal solutions is to remove nums[0], nums[2] and nums[3].
12 * </div>
13 * <strong class="example">Example 2:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [1,3,2,1,3,3]</span>
16 * Output: <span class="example-io">2</span>
17 * Explanation:
18 * One of the optimal solutions is to remove nums[1] and nums[2].
19 * </div>
20 * <strong class="example">Example 3:
21 * <div class="example-block">
22 * Input: <span class="example-io">nums = [2,2,2,2,3,3]</span>
23 * Output: <span class="example-io">0</span>
24 * Explanation:
25 * nums is already non-decreasing.
26 * </div>
27 *
28 * Constraints:
29 *
30 * 1 <= nums.length <= 100
31 * 1 <= nums[i] <= 3
32 *
33 *
34 * Follow-up: Can you come up with an algorithm that runs in O(n) time complexity?
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/sorting-three-groups/
39// discuss: https://leetcode.com/problems/sorting-three-groups/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn minimum_operations(nums: Vec<i32>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2826() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.