Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions problems/length-of-last-word/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@

## 58. Length of Last Word (Easy)

<p>Given a string <i>s</i> consists of upper/lower-case alphabets and empty space characters <code>' '</code>, return the length of last word in the string.</p>
<p>Given a string <i>s</i> consists of upper/lower-case alphabets and empty space characters <code>&#39; &#39;</code>, return the length of last word in the string.</p>

<p>If the last word does not exist, return 0.</p>

<p><b>Note:</b> A word is defined as a character sequence consists of non-space characters only.</p>

<p><b>Example:</b>
<p><b>Example:</b></p>

<pre>
<b>Input:</b> "Hello World"
<b>Input:</b> &quot;Hello World&quot;
<b>Output:</b> 5
</pre>
</p>

<p>&nbsp;</p>

### Related Topics
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]
35 changes: 19 additions & 16 deletions problems/maximum-sum-of-3-non-overlapping-subarrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@

## 689. Maximum Sum of 3 Non-Overlapping Subarrays (Hard)

<p>
In a given array <code>nums</code> of positive integers, find three non-overlapping subarrays with maximum sum.
</p>
<p>
Each subarray will be of size <code>k</code>, and we want to maximize the sum of all <code>3*k</code> entries.
</p>
<p>
Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.
</p>
<p><b>Example:</b><br />
<p>In a given array <code>nums</code> of positive integers, find three non-overlapping subarrays with maximum sum.</p>

<p>Each subarray will be of size <code>k</code>, and we want to maximize the sum of all <code>3*k</code> entries.</p>

<p>Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple answers, return the lexicographically smallest one.</p>

<p><b>Example:</b></p>

<pre>
<b>Input:</b> [1,2,1,2,6,7,5,1], 2
<b>Output:</b> [0, 3, 5]
<b>Explanation:</b> Subarrays [1, 2], [2, 6], [7, 5] correspond to the starting indices [0, 3, 5].
We could have also taken [2, 1], but an answer of [1, 3, 5] would be lexicographically larger.
</pre>
</p>

<p><b>Note:</b><br />
<li><code>nums.length</code> will be between 1 and 20000.</li>
<li><code>nums[i]</code> will be between 1 and 65535.</li>
<li><code>k</code> will be between 1 and floor(nums.length / 3).</li>
</p>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ul>
<li><code>nums.length</code> will be between 1 and 20000.</li>
<li><code>nums[i]</code> will be between 1 and 65535.</li>
<li><code>k</code> will be between 1 and floor(nums.length / 3).</li>
</ul>

<p>&nbsp;</p>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
Expand Down
18 changes: 6 additions & 12 deletions problems/minimize-malware-spread/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,25 @@
<ol>
</ol>

<div>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input: </strong>graph = <span id="example-input-1-1">[[1,1,0],[1,1,0],[0,0,1]]</span>, initial = <span id="example-input-1-2">[0,1]</span>
<strong>Output: </strong><span id="example-output-1">0</span>
<strong>Input: </strong>graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]
<strong>Output: </strong>0
</pre>

<div>
<p><strong>Example 2:</strong></p>

<pre>
<strong>Input: </strong>graph = <span id="example-input-2-1">[[1,0,0],[0,1,0],[0,0,1]]</span>, initial = <span id="example-input-2-2">[0,2]</span>
<strong>Output: </strong><span id="example-output-2">0</span>
<strong>Input: </strong>graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]
<strong>Output: </strong>0
</pre>

<div>
<p><strong>Example 3:</strong></p>

<pre>
<strong>Input: </strong>graph = <span id="example-input-3-1">[[1,1,1],[1,1,1],[1,1,1]]</span>, initial = <span id="example-input-3-2">[1,2]</span>
<strong>Output: </strong><span id="example-output-3">1</span>
<strong>Input: </strong>graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]
<strong>Output: </strong>1
</pre>

<p>&nbsp;</p>
Expand All @@ -61,9 +58,6 @@
<li><code>1 &lt;= initial.length &lt; graph.length</code></li>
<li><code>0 &lt;= initial[i] &lt; graph.length</code></li>
</ol>
</div>
</div>
</div>

### Related Topics
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]
Expand Down
34 changes: 19 additions & 15 deletions problems/ones-and-zeroes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,41 @@
## 474. Ones and Zeroes (Medium)

<p>In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.</p>

<p>For now, suppose you are a dominator of <b>m</b> <code>0s</code> and <b>n</b> <code>1s</code> respectively. On the other hand, there is an array with strings consisting of only <code>0s</code> and <code>1s</code>.</p>

<p>
Now your task is to find the maximum number of strings that you can form with given <b>m</b> <code>0s</code> and <b>n</b> <code>1s</code>. Each <code>0</code> and <code>1</code> can be used at most <b>once</b>.
</p>
<p>Now your task is to find the maximum number of strings that you can form with given <b>m</b> <code>0s</code> and <b>n</b> <code>1s</code>. Each <code>0</code> and <code>1</code> can be used at most <b>once</b>.</p>

<p><b>Note:</b></p>

<p><b>Note:</b><br>
<ol>
<li>The given numbers of <code>0s</code> and <code>1s</code> will both not exceed <code>100</code></li>
<li>The size of given string array won't exceed <code>600</code>.</li>
<li>The given numbers of <code>0s</code> and <code>1s</code> will both not exceed <code>100</code></li>
<li>The size of given string array won&#39;t exceed <code>600</code>.</li>
</ol>
</p>

<p><b>Example 1:</b><br />
<p>&nbsp;</p>

<p><b>Example 1:</b></p>

<pre>
<b>Input:</b> Array = {"10", "0001", "111001", "1", "0"}, m = 5, n = 3
<b>Input:</b> Array = {&quot;10&quot;, &quot;0001&quot;, &quot;111001&quot;, &quot;1&quot;, &quot;0&quot;}, m = 5, n = 3
<b>Output:</b> 4

<b>Explanation:</b> This are totally 4 strings can be formed by the using of 5 0s and 3 1s, which are 10,0001”,”1”,”0”
<b>Explanation:</b> This are totally 4 strings can be formed by the using of 5 0s and 3 1s, which are &ldquo;10,&rdquo;0001&rdquo;,&rdquo;1&rdquo;,&rdquo;0&rdquo;
</pre>
</p>

<p><b>Example 2:</b><br />
<p>&nbsp;</p>

<p><b>Example 2:</b></p>

<pre>
<b>Input:</b> Array = {"10", "0", "1"}, m = 1, n = 1
<b>Input:</b> Array = {&quot;10&quot;, &quot;0&quot;, &quot;1&quot;}, m = 1, n = 1
<b>Output:</b> 2

<b>Explanation:</b> You could form "10", but then you'd have nothing left. Better form "0" and "1".
<b>Explanation:</b> You could form &quot;10&quot;, but then you&#39;d have nothing left. Better form &quot;0&quot; and &quot;1&quot;.
</pre>
</p>

<p>&nbsp;</p>

### Related Topics
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
Expand Down
55 changes: 29 additions & 26 deletions problems/pyramid-transition-matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,52 @@

## 756. Pyramid Transition Matrix (Medium)

<p>
We are stacking blocks to form a pyramid. Each block has a color which is a one letter string, like `'Z'`.
</p><p>
For every block of color `C` we place not in the bottom row, we are placing it on top of a left block of color `A` and right block of color `B`. We are allowed to place the block there only if `(A, B, C)` is an allowed triple.
</p><p>
We start with a bottom row of <code>bottom</code>, represented as a single string. We also start with a list of allowed triples <code>allowed</code>. Each allowed triple is represented as a string of length 3.
</p><p>
Return true if we can build the pyramid all the way to the top, otherwise false.
</p>

<p><b>Example 1:</b><br />
<p>We are stacking blocks to form a pyramid. Each block has a color which is a one letter string.</p>

<p>We are allowed to place any color block <code>C</code> on top of two adjacent blocks of colors <code>A</code> and <code>B</code>, if and only if <code>ABC</code> is an allowed triple.</p>

<p>We start with a bottom row of <code>bottom</code>, represented as a single string. We also start with a list of allowed triples <code>allowed</code>. Each allowed triple is represented as a string of length 3.</p>

<p>Return true if we can build the pyramid all the way to the top, otherwise false.</p>

<p><b>Example 1:</b></p>

<pre>
<b>Input:</b> bottom = "XYZ", allowed = ["XYD", "YZE", "DEA", "FFF"]
<b>Input:</b> bottom = &quot;BCD&quot;, allowed = [&quot;BCG&quot;, &quot;CDE&quot;, &quot;GEA&quot;, &quot;FFF&quot;]
<b>Output:</b> true
<b>Explanation:</b>
We can stack the pyramid like this:
A
/ \
D E
G E
/ \ / \
X Y Z
B C D

This works because ('X', 'Y', 'D'), ('Y', 'Z', 'E'), and ('D', 'E', 'A') are allowed triples.
</pre>
</p>
We are allowed to place G on top of B and C because BCG is an allowed triple. Similarly, we can place E on top of C and D, then A on top of G and E.</pre>

<p>&nbsp;</p>

<p><b>Example 2:</b></p>

<p><b>Example 2:</b><br />
<pre>
<b>Input:</b> bottom = "XXYX", allowed = ["XXX", "XXY", "XYX", "XYY", "YXZ"]
<b>Input:</b> bottom = &quot;AABA&quot;, allowed = [&quot;AAA&quot;, &quot;AAB&quot;, &quot;ABA&quot;, &quot;ABB&quot;, &quot;BAC&quot;]
<b>Output:</b> false
<b>Explanation:</b>
We can't stack the pyramid to the top.
We can&#39;t stack the pyramid to the top.
Note that there could be allowed triples (A, B, C) and (A, B, D) with C != D.
</pre>
</p>

<p><b>Note:</b><br>
<p>&nbsp;</p>

<p><b>Note:</b></p>

<ol>
<li><code>bottom</code> will be a string with length in range <code>[2, 8]</code>.</li>
<li><code>allowed</code> will have length in range <code>[0, 200]</code>.</li>
<li>Letters in all strings will be chosen from the set <code>{'A', 'B', 'C', 'D', 'E', 'F', 'G'}</code>.</li>
<li><code>bottom</code> will be a string with length in range <code>[2, 8]</code>.</li>
<li><code>allowed</code> will have length in range <code>[0, 200]</code>.</li>
<li>Letters in all strings will be chosen from the set <code>{&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, &#39;F&#39;, &#39;G&#39;}</code>.</li>
</ol>
</p>

<p>&nbsp;</p>

### Related Topics
[[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)]
Expand Down
9 changes: 8 additions & 1 deletion problems/uncrossed-lines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@

<p>We write the integers of <code>A</code> and <code>B</code>&nbsp;(in the order they are given) on two separate horizontal lines.</p>

<p>Now, we may draw a straight line connecting two numbers <code>A[i]</code> and <code>B[j]</code> as long as <code>A[i] == B[j]</code>, and the line we draw does not intersect any other connecting (non-horizontal) line.</p>
<p>Now, we may draw <em>connecting lines</em>: a straight line connecting two numbers <code>A[i]</code> and <code>B[j]</code>&nbsp;such that:</p>

<ul>
<li><code>A[i] == B[j]</code>;</li>
<li>The line we draw does not intersect any other connecting (non-horizontal) line.</li>
</ul>

<p>Note that a connecting lines cannot intersect even at the endpoints:&nbsp;each number can only belong to one connecting line.</p>

<p>Return the maximum number of connecting lines we can draw in this way.</p>

Expand Down
18 changes: 11 additions & 7 deletions problems/valid-square/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@

<p>The coordinate (x,y) of a point is represented by an integer array with two integers.</p>

<p><b>Example:</b><br />
<p><b>Example:</b></p>

<pre>
<b>Input:</b> p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]
<b>Output:</b> True
</pre>
</p>

<p> Note:
<p>&nbsp;</p>

<p>Note:</p>

<ol>
<li>All the input integers are in the range [-10000, 10000].</li>
<li>A valid square has four equal sides with positive length and four equal angles (90-degree angles).</li>
<li>Input points have no order.</li>
<li>All the input integers are in the range [-10000, 10000].</li>
<li>A valid square has four equal sides with positive length and four equal angles (90-degree angles).</li>
<li>Input points have no order.</li>
</ol>
</p>

<p>&nbsp;</p>

### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]