You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2800-2899/2826.Sorting Three Groups/README_EN.md
+29-43
Original file line number
Diff line number
Diff line change
@@ -6,61 +6,44 @@
6
6
7
7
## Description
8
8
9
-
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>.<br />
10
-
<br />
11
-
The numbers from <code>0</code> to <code>n - 1</code> are divided into three groups numbered from <code>1</code> to <code>3</code>, where number <code>i</code> belongs to group <code>nums[i]</code>. Notice that some groups may be <strong>empty</strong>.<br />
12
-
<br />
13
-
You are allowed to perform this operation any number of times:</p>
9
+
<p>You are given an integer array <code>nums</code>. Each element in <code>nums</code> is 1, 2 or 3. In each operation, you can remove an element from <code>nums</code>. Return the <strong>minimum</strong> number of operations to make <code>nums</code> <strong>non-decreasing</strong>.</p>
14
10
15
-
<ul>
16
-
<li>Pick number <code>x</code> and change its group. More formally, change <code>nums[x]</code> to any number from <code>1</code> to <code>3</code>.</li>
17
-
</ul>
11
+
<p> </p>
12
+
<p><strongclass="example">Example 1:</strong></p>
18
13
19
-
<p>A new array <code>res</code> is constructed using the following procedure:</p>
<p>Array <code>nums</code> is called a <strong>beautiful array</strong> if the constructed array <code>res</code> is sorted in <strong>non-decreasing</strong> order.</p>
19
+
<p><strong>Explanation:</strong></p>
27
20
28
-
<p>Return <em>the <strong>minimum</strong> number of operations to make </em><code>nums</code><em> a <strong>beautiful array</strong></em>.</p>
21
+
<p>One of the optimal solutions is to remove <code>nums[0]</code>, <code>nums[2]</code> and <code>nums[3]</code>.</p>
22
+
</div>
29
23
30
-
<p> </p>
31
-
<p><strongclass="example">Example 1:</strong></p>
24
+
<p><strongclass="example">Example 2:</strong></p>
32
25
33
-
<pre>
34
-
<strong>Input:</strong> nums = [2,1,3,2,1]
35
-
<strong>Output:</strong> 3
36
-
<strong>Explanation:</strong> It's optimal to perform three operations:
37
-
1. change nums[0] to 1.
38
-
2. change nums[2] to 1.
39
-
3. change nums[3] to 1.
40
-
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3,4] and group 2 and group 3 become empty. Hence, res is equal to [0,1,2,3,4] which is sorted in non-decreasing order.
41
-
It can be proven that there is no valid sequence of less than three operations.
<strong>Explanation:</strong> It's optimal to perform two operations:
50
-
1. change nums[1] to 1.
51
-
2. change nums[2] to 1.
52
-
After performing the operations and sorting the numbers in each group, group 1 becomes equal to [0,1,2,3], group 2 becomes empty, and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.
53
-
It can be proven that there is no valid sequence of less than two operations.
54
-
</pre>
33
+
<p>One of the optimal solutions is to remove <code>nums[1]</code> and <code>nums[2]</code>.</p>
34
+
</div>
55
35
56
36
<p><strongclass="example">Example 3:</strong></p>
57
37
58
-
<pre>
59
-
<strong>Input:</strong> nums = [2,2,2,2,3,3]
60
-
<strong>Output:</strong> 0
61
-
<strong>Explanation:</strong> It's optimal to not perform operations.
62
-
After sorting the numbers in each group, group 1 becomes empty, group 2 becomes equal to [0,1,2,3] and group 3 becomes equal to [4,5]. Hence, res is equal to [0,1,2,3,4,5] which is sorted in non-decreasing order.
0 commit comments