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
2 changes: 1 addition & 1 deletion problems/best-time-to-buy-and-sell-stock-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

### Similar Questions
1. [Best Time to Buy and Sell Stock](https://github.com/openset/leetcode/tree/master/problems/best-time-to-buy-and-sell-stock) (Easy)
Expand Down
2 changes: 1 addition & 1 deletion problems/insertion-sort-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ With each iteration one element (red) is removed from the input data and inserte
</pre>

### Related Topics
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)]
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)]

### Similar Questions
1. [Sort List](https://github.com/openset/leetcode/tree/master/problems/sort-list) (Medium)
Expand Down
41 changes: 41 additions & 0 deletions problems/maximum-of-absolute-value-expression/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-cost-tree-from-leaf-values "Minimum Cost Tree From Leaf Values")

Next >

## 1131. Maximum of Absolute Value Expression (Medium)

<p>Given two arrays of integers with equal lengths, return the maximum value of:</p>

<p><code>|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|</code></p>

<p>where the maximum is taken over all <code>0 &lt;= i, j &lt; arr1.length</code>.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
<strong>Output:</strong> 13
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
<strong>Output:</strong> 20
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>2 &lt;= arr1.length == arr2.length &lt;= 40000</code></li>
<li><code>-10^6 &lt;= arr1[i], arr2[i] &lt;= 10^6</code></li>
</ul>
47 changes: 47 additions & 0 deletions problems/minimum-cost-tree-from-leaf-values/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/shortest-path-with-alternating-colors "Shortest Path with Alternating Colors")

[Next >](https://github.com/openset/leetcode/tree/master/problems/maximum-of-absolute-value-expression "Maximum of Absolute Value Expression")

## 1130. Minimum Cost Tree From Leaf Values (Medium)

<p>Given an array <code>arr</code> of positive integers, consider all binary trees such that:</p>

<ul>
<li>Each node has either 0 or 2 children;</li>
<li>The values of <code>arr</code> correspond to the values of each&nbsp;<strong>leaf</strong> in an in-order traversal of the tree.&nbsp; <em>(Recall that a node is a leaf if and only if it has 0 children.)</em></li>
<li>The value&nbsp;of each non-leaf node is equal to the product of the largest leaf value in its left and right subtree respectively.</li>
</ul>

<p>Among all possible binary trees considered,&nbsp;return the smallest possible sum of the values of each non-leaf node.&nbsp; It is guaranteed this sum fits into a 32-bit integer.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr = [6,2,4]
<strong>Output:</strong> 32
<strong>Explanation:</strong>
There are two possible trees. The first has non-leaf node sum 36, and the second has non-leaf node sum 32.

24 24
/ \ / \
12 4 6 8
/ \ / \
6 2 2 4
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>2 &lt;= arr.length &lt;= 40</code></li>
<li><code>1 &lt;= arr[i] &lt;= 15</code></li>
<li>It is guaranteed that the answer fits into a 32-bit signed integer (ie.&nbsp;it is less than <code>2^31</code>).</li>
</ul>
29 changes: 29 additions & 0 deletions problems/number-of-equivalent-domino-pairs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/user-purchase-platform "User Purchase Platform")

[Next >](https://github.com/openset/leetcode/tree/master/problems/shortest-path-with-alternating-colors "Shortest Path with Alternating Colors")

## 1128. Number of Equivalent Domino Pairs (Easy)

<p>Given a list of <code>dominoes</code>,&nbsp;<code>dominoes[i] = [a, b]</code>&nbsp;is <em>equivalent</em> to <code>dominoes[j] = [c, d]</code>&nbsp;if and only if either (<code>a==c</code> and <code>b==d</code>), or (<code>a==d</code> and <code>b==c</code>) - that is, one domino can be rotated to be equal to another domino.</p>

<p>Return the number of pairs <code>(i, j)</code> for which <code>0 &lt;= i &lt; j &lt; dominoes.length</code>, and&nbsp;<code>dominoes[i]</code> is equivalent to <code>dominoes[j]</code>.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre><strong>Input:</strong> dominoes = [[1,2],[2,1],[3,4],[5,6]]
<strong>Output:</strong> 1
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= dominoes.length &lt;= 40000</code></li>
<li><code>1 &lt;= dominoes[i][j] &lt;= 9</code></li>
</ul>
46 changes: 46 additions & 0 deletions problems/shortest-path-with-alternating-colors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/number-of-equivalent-domino-pairs "Number of Equivalent Domino Pairs")

[Next >](https://github.com/openset/leetcode/tree/master/problems/minimum-cost-tree-from-leaf-values "Minimum Cost Tree From Leaf Values")

## 1129. Shortest Path with Alternating Colors (Medium)

<p>Consider a directed graph, with nodes labelled <code>0, 1, ..., n-1</code>.&nbsp; In this graph, each edge is either red or blue, and there could&nbsp;be self-edges or parallel edges.</p>

<p>Each <code>[i, j]</code> in <code>red_edges</code> denotes a red directed edge from node <code>i</code> to node <code>j</code>.&nbsp; Similarly, each <code>[i, j]</code> in <code>blue_edges</code> denotes a blue directed edge from node <code>i</code> to node <code>j</code>.</p>

<p>Return an array <code>answer</code>&nbsp;of length <code>n</code>,&nbsp;where each&nbsp;<code>answer[X]</code>&nbsp;is&nbsp;the length of the shortest path from node <code>0</code>&nbsp;to node <code>X</code>&nbsp;such that the edge colors alternate along the path (or <code>-1</code> if such a path doesn&#39;t exist).</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre><strong>Input:</strong> n = 3, red_edges = [[0,1],[1,2]], blue_edges = []
<strong>Output:</strong> [0,1,-1]
</pre><p><strong>Example 2:</strong></p>
<pre><strong>Input:</strong> n = 3, red_edges = [[0,1]], blue_edges = [[2,1]]
<strong>Output:</strong> [0,1,-1]
</pre><p><strong>Example 3:</strong></p>
<pre><strong>Input:</strong> n = 3, red_edges = [[1,0]], blue_edges = [[2,1]]
<strong>Output:</strong> [0,-1,-1]
</pre><p><strong>Example 4:</strong></p>
<pre><strong>Input:</strong> n = 3, red_edges = [[0,1]], blue_edges = [[1,2]]
<strong>Output:</strong> [0,1,2]
</pre><p><strong>Example 5:</strong></p>
<pre><strong>Input:</strong> n = 3, red_edges = [[0,1],[0,2]], blue_edges = [[1,0]]
<strong>Output:</strong> [0,1,1]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 100</code></li>
<li><code>red_edges.length &lt;= 400</code></li>
<li><code>blue_edges.length &lt;= 400</code></li>
<li><code>red_edges[i].length == blue_edges[i].length == 2</code></li>
<li><code>0 &lt;= red_edges[i][j], blue_edges[i][j] &lt; n</code></li>
</ul>
2 changes: 1 addition & 1 deletion problems/sort-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<strong>Output:</strong> -1-&gt;0-&gt;3-&gt;4-&gt;5</pre>

### Related Topics
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)]
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
[[Linked List](https://github.com/openset/leetcode/tree/master/tag/linked-list/README.md)]

### Similar Questions
1. [Merge Two Sorted Lists](https://github.com/openset/leetcode/tree/master/problems/merge-two-sorted-lists) (Easy)
Expand Down