Practice Sorting Three Groups
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
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.
Source: Sorting Three Groups on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [2,1,3,2,1]
Output
3
# Example 2
Input
nums = [1,3,2,1,3,3]
Output
2
# Example 3
Input
nums = [2,2,2,2,3,3]
Output
0
Constraints
1 <= nums.length <= 100
1 <= nums[i] <= 3
Related LeetCode Problems
Practice more problems similar to Sorting Three Groups.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.