diff --git a/problems/best-time-to-buy-and-sell-stock-ii/README.md b/problems/best-time-to-buy-and-sell-stock-ii/README.md index 4257b8cc1..a379f0e32 100644 --- a/problems/best-time-to-buy-and-sell-stock-ii/README.md +++ b/problems/best-time-to-buy-and-sell-stock-ii/README.md @@ -44,8 +44,8 @@ Explanation: In this case, no transaction is done, i.e. max profit = 0. ### 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) diff --git a/problems/insertion-sort-list/README.md b/problems/insertion-sort-list/README.md index 72eff798a..ccb768d9d 100644 --- a/problems/insertion-sort-list/README.md +++ b/problems/insertion-sort-list/README.md @@ -48,8 +48,8 @@ With each iteration one element (red) is removed from the input data and inserte ### 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) diff --git a/problems/maximum-of-absolute-value-expression/README.md b/problems/maximum-of-absolute-value-expression/README.md new file mode 100644 index 000000000..5d16b18b8 --- /dev/null +++ b/problems/maximum-of-absolute-value-expression/README.md @@ -0,0 +1,41 @@ + + + + + + + +[< 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) + +

Given two arrays of integers with equal lengths, return the maximum value of:

+ +

|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|

+ +

where the maximum is taken over all 0 <= i, j < arr1.length.

+ +

 

+

Example 1:

+ +
+Input: arr1 = [1,2,3,4], arr2 = [-1,4,5,6]
+Output: 13
+
+ +

Example 2:

+ +
+Input: arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]
+Output: 20
+
+ +

 

+

Constraints:

+ + diff --git a/problems/minimum-cost-tree-from-leaf-values/README.md b/problems/minimum-cost-tree-from-leaf-values/README.md new file mode 100644 index 000000000..fa8d35f3a --- /dev/null +++ b/problems/minimum-cost-tree-from-leaf-values/README.md @@ -0,0 +1,47 @@ + + + + + + + +[< 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) + +

Given an array arr of positive integers, consider all binary trees such that:

+ + + +

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

+ +

 

+

Example 1:

+ +
+Input: arr = [6,2,4]
+Output: 32
+Explanation:
+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
+
+ +

 

+

Constraints:

+ + diff --git a/problems/number-of-equivalent-domino-pairs/README.md b/problems/number-of-equivalent-domino-pairs/README.md new file mode 100644 index 000000000..465baf8ed --- /dev/null +++ b/problems/number-of-equivalent-domino-pairs/README.md @@ -0,0 +1,29 @@ + + + + + + + +[< 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) + +

Given a list of dominoesdominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a==c and b==d), or (a==d and b==c) - that is, one domino can be rotated to be equal to another domino.

+ +

Return the number of pairs (i, j) for which 0 <= i < j < dominoes.length, and dominoes[i] is equivalent to dominoes[j].

+ +

 

+

Example 1:

+
Input: dominoes = [[1,2],[2,1],[3,4],[5,6]]
+Output: 1
+
+

 

+

Constraints:

+ + diff --git a/problems/shortest-path-with-alternating-colors/README.md b/problems/shortest-path-with-alternating-colors/README.md new file mode 100644 index 000000000..b0009b288 --- /dev/null +++ b/problems/shortest-path-with-alternating-colors/README.md @@ -0,0 +1,46 @@ + + + + + + + +[< 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) + +

Consider a directed graph, with nodes labelled 0, 1, ..., n-1.  In this graph, each edge is either red or blue, and there could be self-edges or parallel edges.

+ +

Each [i, j] in red_edges denotes a red directed edge from node i to node j.  Similarly, each [i, j] in blue_edges denotes a blue directed edge from node i to node j.

+ +

Return an array answer of length n, where each answer[X] is the length of the shortest path from node 0 to node X such that the edge colors alternate along the path (or -1 if such a path doesn't exist).

+ +

 

+

Example 1:

+
Input: n = 3, red_edges = [[0,1],[1,2]], blue_edges = []
+Output: [0,1,-1]
+

Example 2:

+
Input: n = 3, red_edges = [[0,1]], blue_edges = [[2,1]]
+Output: [0,1,-1]
+

Example 3:

+
Input: n = 3, red_edges = [[1,0]], blue_edges = [[2,1]]
+Output: [0,-1,-1]
+

Example 4:

+
Input: n = 3, red_edges = [[0,1]], blue_edges = [[1,2]]
+Output: [0,1,2]
+

Example 5:

+
Input: n = 3, red_edges = [[0,1],[0,2]], blue_edges = [[1,0]]
+Output: [0,1,1]
+
+

 

+

Constraints:

+ + diff --git a/problems/sort-list/README.md b/problems/sort-list/README.md index 22cf9683f..46456c7b3 100644 --- a/problems/sort-list/README.md +++ b/problems/sort-list/README.md @@ -27,8 +27,8 @@ Output: -1->0->3->4->5 ### 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)