Tap here to switch tabs
Problem
Submissions

Problem: Sorting Three Groups

Sorting Three Groups gives an array of ones, twos, and threes. Return the fewest value changes needed to make the array nondecreasing, with each operation choosing any replacement from one to three.

Statement

You are given an integer array nums where every element is either 11, 22, or 33.

In one operation, you can select any index and change its value to any integer from 11 to 33, inclusive.

Return the minimum number of operations required to make nums nondecreasing.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤3\leq 3

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sorting Three Groups

Sorting Three Groups gives an array of ones, twos, and threes. Return the fewest value changes needed to make the array nondecreasing, with each operation choosing any replacement from one to three.

Statement

You are given an integer array nums where every element is either 11, 22, or 33.

In one operation, you can select any index and change its value to any integer from 11 to 33, inclusive.

Return the minimum number of operations required to make nums nondecreasing.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤3\leq 3