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/1400-1499/1438.Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit/README_EN.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,11 @@ Therefore, the size of the longest subarray is 2.
75
75
76
76
<!-- solution:start -->
77
77
78
-
### Solution 1
78
+
### Solution 1: Ordered Set + Sliding Window
79
+
80
+
We can enumerate each position as the right endpoint of the subarray, and find the leftmost left endpoint corresponding to it, such that the difference between the maximum and minimum values in the interval does not exceed $limit$. During the process, we use an ordered set to maintain the maximum and minimum values within the window.
81
+
82
+
The time complexity is $O(n \log n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the array `nums`.
Copy file name to clipboardExpand all lines: solution/2700-2799/2732.Find a Good Subset of the Matrix/README_EN.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,7 @@ The length of the chosen subset is 1.
87
87
We can consider the number of rows $k$ chosen for the answer from smallest to largest.
88
88
89
89
- If $k = 1$, the maximum sum of each column is $0$. Therefore, there must be a row where all elements are $0$, otherwise, the condition cannot be met.
90
-
- If $k = 2$, the maximum sum of each column is $1$. There must exist two rows, and the bitwise OR result of these two rows' elements is $0$, otherwise, the condition cannot be met.
90
+
- If $k = 2$, the maximum sum of each column is $1$. There must exist two rows, and the bitwise AND result of these two rows' elements is $0$, otherwise, the condition cannot be met.
91
91
- If $k = 3$, the maximum sum of each column is also $1$. If the condition for $k = 2$ is not met, then the condition for $k = 3$ will definitely not be met either. Therefore, we do not need to consider any case where $k > 2$ and $k$ is odd.
92
92
- If $k = 4$, the maximum sum of each column is $2$. This situation definitely occurs when the condition for $k = 2$ is not met, meaning that for any two selected rows, there exists at least one column with a sum of $2$. When choosing any 2 rows out of 4, there are a total of $C_4^2 = 6$ ways to choose, so there are at least $6$ columns with a sum of $2$. Since the number of columns $n \le 5$, there must be at least one column with a sum greater than $2$, so the condition for $k = 4$ is also not met.
93
93
- For $k > 4$ and $k$ being even, we can draw the same conclusion, that $k$ definitely does not meet the condition.
Copy file name to clipboardExpand all lines: solution/2900-2999/2966.Divide Array Into Arrays With Max Difference/README_EN.md
+42-18
Original file line number
Diff line number
Diff line change
@@ -20,43 +20,67 @@ tags:
20
20
21
21
<!-- description:start -->
22
22
23
-
<p>You are given an integer array <code>nums</code> of size <code>n</code> and a positive integer <code>k</code>.</p>
23
+
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is a multiple of 3 and a positive integer <code>k</code>.</p>
24
24
25
-
<p>Divide the array into one or more arrays of size <code>3</code> satisfying the following conditions:</p>
25
+
<p>Divide the array <code>nums</code> into <code>n / 3</code> arrays of size <strong>3</strong> satisfying the following condition:</p>
26
26
27
27
<ul>
28
-
<li><strong>Each</strong> element of <code>nums</code> should be in <strong>exactly</strong> one array.</li>
29
-
<li>The difference between <strong>any</strong> two elements in one array is less than or equal to <code>k</code>.</li>
28
+
<li>The difference between <strong>any</strong> two elements in one array is <strong>less than or equal</strong> to <code>k</code>.</li>
30
29
</ul>
31
30
32
-
<p>Return <em>a </em><strong>2D</strong><em> array containing all the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return <strong>any</strong> of them.</em></p>
31
+
<p>Return a <strong>2D</strong> array containing the arrays. If it is impossible to satisfy the conditions, return an empty array. And if there are multiple answers, return <strong>any</strong> of them.</p>
33
32
34
33
<p> </p>
35
34
<p><strongclass="example">Example 1:</strong></p>
36
35
37
-
<pre>
38
-
<strong>Input:</strong> nums = [1,3,4,8,7,9,3,5,1], k = 2
<p>Different ways to divide <code>nums</code> into 2 arrays of size 3 are:</p>
56
+
57
+
<ul>
58
+
<li>[[2,2,2],[2,4,5]] (and its permutations)</li>
59
+
<li>[[2,2,4],[2,2,5]] (and its permutations)</li>
60
+
</ul>
61
+
62
+
<p>Because there are four 2s there will be an array with the elements 2 and 5 no matter how we divide it. since <code>5 - 2 = 3 > k</code>, the condition is not satisfied and so there is no valid division.</p>
63
+
</div>
64
+
65
+
<p><strongclass="example">Example 3:</strong></p>
66
+
67
+
<divclass="example-block">
68
+
<p><strong>Input:</strong> <spanclass="example-io">nums = [4,2,9,8,2,12,7,12,10,5,8,5,5,7,9,2,5,11], k = 14</span></p>
0 commit comments