Skip to content

Commit 22faaff

Browse files
committed
Create README - LeetHub
1 parent e9ae4f5 commit 22faaff

File tree

1 file changed

+44
-0
lines changed
  • 1633-minimum-number-of-increments-on-subarrays-to-form-a-target-array

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<h2><a href="https://leetcode.com/problems/minimum-number-of-increments-on-subarrays-to-form-a-target-array">1633. Minimum Number of Increments on Subarrays to Form a Target Array</a></h2><h3>Hard</h3><hr><p>You are given an integer array <code>target</code>. You have an integer array <code>initial</code> of the same size as <code>target</code> with all elements initially zeros.</p>
2+
3+
<p>In one operation you can choose <strong>any</strong> subarray from <code>initial</code> and increment each value by one.</p>
4+
5+
<p>Return <em>the minimum number of operations to form a </em><code>target</code><em> array from </em><code>initial</code>.</p>
6+
7+
<p>The test cases are generated so that the answer fits in a 32-bit integer.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
<pre>
13+
<strong>Input:</strong> target = [1,2,3,2,1]
14+
<strong>Output:</strong> 3
15+
<strong>Explanation:</strong> We need at least 3 operations to form the target array from the initial array.
16+
[<strong><u>0,0,0,0,0</u></strong>] increment 1 from index 0 to 4 (inclusive).
17+
[1,<strong><u>1,1,1</u></strong>,1] increment 1 from index 1 to 3 (inclusive).
18+
[1,2,<strong><u>2</u></strong>,2,1] increment 1 at index 2.
19+
[1,2,3,2,1] target array is formed.
20+
</pre>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> target = [3,1,1,2]
26+
<strong>Output:</strong> 4
27+
<strong>Explanation:</strong> [<strong><u>0,0,0,0</u></strong>] -&gt; [1,1,1,<strong><u>1</u></strong>] -&gt; [<strong><u>1</u></strong>,1,1,2] -&gt; [<strong><u>2</u></strong>,1,1,2] -&gt; [3,1,1,2]
28+
</pre>
29+
30+
<p><strong class="example">Example 3:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> target = [3,1,5,4,2]
34+
<strong>Output:</strong> 7
35+
<strong>Explanation:</strong> [<strong><u>0,0,0,0,0</u></strong>] -&gt; [<strong><u>1</u></strong>,1,1,1,1] -&gt; [<strong><u>2</u></strong>,1,1,1,1] -&gt; [3,1,<strong><u>1,1,1</u></strong>] -&gt; [3,1,<strong><u>2,2</u></strong>,2] -&gt; [3,1,<strong><u>3,3</u></strong>,2] -&gt; [3,1,<strong><u>4</u></strong>,4,2] -&gt; [3,1,5,4,2].
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
<p><strong>Constraints:</strong></p>
40+
41+
<ul>
42+
<li><code>1 &lt;= target.length &lt;= 10<sup>5</sup></code></li>
43+
<li><code>1 &lt;= target[i] &lt;= 10<sup>5</sup></code></li>
44+
</ul>

0 commit comments

Comments
 (0)