#2826

Sorting Three Groups

medium · 42.9% accepted · 525 likes · top 24%

array · binary search · dynamic programming

Description

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.

Solution