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/2500-2599/2567.Minimum Score by Changing Two Elements/README_EN.md
+31-22
Original file line number
Diff line number
Diff line change
@@ -20,39 +20,48 @@ tags:
20
20
21
21
<!-- description:start -->
22
22
23
-
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p>
23
+
<p>You are given an integer array <code>nums</code>.</p>
24
24
25
25
<ul>
26
-
<li>The <strong>low</strong> score of <code><font face="monospace">nums</font></code> is the minimum value of <code>|nums[i] - nums[j]|</code> over all <code>0 <= i < j < nums.length</code>.</li>
27
-
<li>The <strong>high</strong> score of <code><font face="monospace">nums</font></code> is the maximum value of <code>|nums[i] - nums[j]|</code> over all <code>0 <= i < j < nums.length</code>.</li>
28
-
<li>The <strong>score</strong> of <code>nums</code> is the sum of the <strong>high</strong> and <strong>low</strong> scores of nums.</li>
26
+
<li>The <strong>low</strong> score of <code>nums</code> is the <strong>minimum</strong> absolute difference between any two integers.</li>
27
+
<li>The <strong>high</strong> score of<code>nums</code> is the <strong>maximum</strong> absolute difference between any two integers.</li>
28
+
<li>The <strong>score</strong> of <code>nums</code> is the sum of the <strong>high</strong> and <strong>low</strong> scores.</li>
29
29
</ul>
30
30
31
-
<p>To minimize the score of <code>nums</code>, we can change the value of <strong>at most two</strong> elements of <code>nums</code>.</p>
32
-
33
-
<p>Return <em>the <strong>minimum</strong> possible <strong>score</strong> after changing the value of <strong>at most two</strong> elements o</em>f <code>nums</code>.</p>
34
-
35
-
<p>Note that <code>|x|</code> denotes the absolute value of <code>x</code>.</p>
31
+
<p>Return the <strong>minimum score</strong> after <strong>changing two elements</strong> of <code>nums</code>.</p>
36
32
37
33
<p> </p>
38
34
<p><strongclass="example">Example 1:</strong></p>
39
35
40
-
<pre>
41
-
<strong>Input:</strong> nums = [1,4,3]
42
-
<strong>Output:</strong> 0
43
-
<strong>Explanation:</strong> Change value of nums[1] and nums[2] to 1 so that nums becomes [1,1,1]. Now, the value of <code>|nums[i] - nums[j]|</code> is always equal to 0, so we return 0 + 0 = 0.
Copy file name to clipboardexpand all lines: solution/2600-2699/2612.Minimum Reverse Operations/README_EN.md
+40-25
Original file line number
Diff line number
Diff line change
@@ -20,44 +20,59 @@ tags:
20
20
21
21
<!-- description:start -->
22
22
23
-
<p>You are given an integer <code>n</code> and an integer <code>p</code> in the range <code>[<fontface="monospace">0</font>, n - 1]</code>. Representing a <strong>0-indexed</strong> array <code>arr</code> of length <code>n</code> where all positions are set to <code>0</code>'s, except position <code>p</code> which is set to <code>1</code>.</p>
24
-
25
-
<p>You are also given an integer array <code>banned</code> containing some positions from the array. For the <strong>i</strong><sup><strong>th</strong></sup> position in <code>banned</code>, <code>arr[banned[i]] = 0</code>, and <code>banned[i] != p</code>.</p>
26
-
27
-
<p>You can perform <strong>multiple</strong> operations on <code>arr</code>. In an operation, you can choose a <strong>subarray</strong> with size <code>k</code> and <strong>reverse</strong> the subarray. However, the <code>1</code> in <code>arr</code> should never go to any of the positions in <code>banned</code>. In other words, after each operation <code>arr[banned[i]]</code> <strong>remains</strong> <code>0</code>.</p>
28
-
29
-
<p><em>Return an array</em> <code>ans</code> <em>where</em><em> for each </em><code>i</code><em> from </em><code>[0, n - 1]</code>, <code>ans[i]</code> <em>is the <strong>minimum</strong> number of reverse operations needed to bring the</em> <code>1</code> <em>to position</em> <code>i</code><em> in arr</em>, <em>or</em> <code>-1</code> <em>if it is impossible</em>.</p>
23
+
<p>You are given an integer <code>n</code> and an integer <code>p</code> representing an array <code>arr</code> of length <code>n</code> where all elements are set to 0's, except position <code>p</code> which is set to 1. You are also given an integer array <code>banned</code> containing restricted positions. Perform the following operation on <code>arr</code>:</p>
30
24
31
25
<ul>
32
-
<li>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</li>
33
-
<li>The values of <code>ans[i]</code> are independent for all <code>i</code>'s.</li>
34
-
<li>The <strong>reverse </strong>of an array is an array containing the values in <strong>reverse order</strong>.</li>
26
+
<li>Reverse a <span data-keyword="subarray-nonempty"><strong>subarray</strong></span> with size <code>k</code> if the single 1 is not set to a position in <code>banned</code>.</li>
35
27
</ul>
36
28
29
+
<p>Return an integer array <code>answer</code> with <code>n</code> results where the <code>i<sup>th</sup></code> result is<em> </em>the <strong>minimum</strong> number of operations needed to bring the single 1 to position <code>i</code> in <code>arr</code>, or -1 if it is impossible.</p>
30
+
37
31
<p> </p>
38
32
<p><strongclass="example">Example 1:</strong></p>
39
33
40
-
<pre>
41
-
<strong>Input:</strong> n = 4, p = 0, banned = [1,2], k = 4
42
-
<strong>Output:</strong> [0,-1,-1,1]
43
-
<strong>Explanation:</strong> In this case <code>k = 4</code> so there is only one possible reverse operation we can perform, which is reversing the whole array. Initially, 1<strong> </strong>is placed at position 0 so the amount of operations we need for position 0 is <code>0</code>. We can never place a 1 on the banned positions, so the answer for positions 1 and 2 is <code>-1</code>. Finally, with one reverse operation we can bring the 1 to index 3, so the answer for position 3 is <code>1</code>.
44
-
</pre>
34
+
<divclass="example-block">
35
+
<p><strong>Input:</strong> <spanclass="example-io">n = 4, p = 0, banned = [1,2], k = 4</span></p>
<li>Initially 1 is placed at position 0 so the number of operations we need for position 0 is 0.</li>
43
+
<li>We can never place 1 on the banned positions, so the answer for positions 1 and 2 is -1.</li>
44
+
<li>Perform the operation of size 4 to reverse the whole array.</li>
45
+
<li>After a single operation 1 is at position 3 so the answer for position 3 is 1.</li>
46
+
</ul>
47
+
</div>
45
48
46
49
<p><strongclass="example">Example 2:</strong></p>
47
50
48
-
<pre>
49
-
<strong>Input:</strong> n = 5, p = 0, banned = [2,4], k = 3
50
-
<strong>Output:</strong> [0,-1,-1,-1,-1]
51
-
<strong>Explanation:</strong> In this case the 1 is initially at position 0, so the answer for that position is <code>0</code>. We can perform reverse operations of size 3. The 1 is currently located at position 0, so we need to reverse the subarray <code>[0, 2]</code> for it to leave that position, but reversing that subarray makes position 2 have a 1, which shouldn't happen. So, we can't move the 1 from position 0, making the result for all the other positions <code>-1</code>.
52
-
</pre>
51
+
<divclass="example-block">
52
+
<p><strong>Input:</strong> <spanclass="example-io">n = 5, p = 0, banned = [2,4], k = 3</span></p>
<li>Initially 1 is placed at position 0 so the number of operations we need for position 0 is 0.</li>
60
+
<li>We cannot perform the operation on the subarray positions <code>[0, 2]</code> because position 2 is in banned.</li>
61
+
<li>Because 1 cannot be set at position 2, it is impossible to set 1 at other positions in more operations.</li>
62
+
</ul>
63
+
</div>
53
64
54
65
<p><strongclass="example">Example 3:</strong></p>
55
66
56
-
<pre>
57
-
<strong>Input:</strong> n = 4, p = 2, banned = [0,1,3], k = 1
58
-
<strong>Output:</strong> [-1,-1,0,-1]
59
-
<strong>Explanation:</strong> In this case we can only perform reverse operations of size 1.<strong> </strong>So the 1 never changes its position.
60
-
</pre>
67
+
<divclass="example-block">
68
+
<p><strong>Input:</strong> <spanclass="example-io">n = 4, p = 2, banned = [0,1,3], k = 1</span></p>
0 commit comments