-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor some promise with batch concurrency
- Loading branch information
Showing
24 changed files
with
339 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-4.55 KB
(27%)
Notes/Questions/0892__surface-area-of-3d-shapes/tmp-grid4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
.../Questions/1886__determine-whether-matrix-can-be-obtained-by-rotation/grid4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Notes/Questions/2200__find-all-k-distant-indices-in-an-array/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Problem Statement | ||
|
||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and two integers <code>key</code> and <code>k</code>. A <strong>k-distant index</strong> is an index <code>i</code> of <code>nums</code> for which there exists at least one index <code>j</code> such that <code>|i - j| <= k</code> and <code>nums[j] == key</code>.</p> | ||
|
||
<p>Return <em>a list of all k-distant indices sorted in <strong>increasing order</strong></em>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [3,4,9,1,3,9,5], key = 9, k = 1 | ||
<strong>Output:</strong> [1,2,3,4,5,6] | ||
<strong>Explanation:</strong> Here, <code>nums[2] == key</code> and <code>nums[5] == key. | ||
- For index 0, |0 - 2| > k and |0 - 5| > k, so there is no j</code> where <code>|0 - j| <= k</code> and <code>nums[j] == key. Thus, 0 is not a k-distant index. | ||
- For index 1, |1 - 2| <= k and nums[2] == key, so 1 is a k-distant index. | ||
- For index 2, |2 - 2| <= k and nums[2] == key, so 2 is a k-distant index. | ||
- For index 3, |3 - 2| <= k and nums[2] == key, so 3 is a k-distant index. | ||
- For index 4, |4 - 5| <= k and nums[5] == key, so 4 is a k-distant index. | ||
- For index 5, |5 - 5| <= k and nums[5] == key, so 5 is a k-distant index. | ||
- For index 6, |6 - 5| <= k and nums[5] == key, so 6 is a k-distant index. | ||
</code>Thus, we return [1,2,3,4,5,6] which is sorted in increasing order. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [2,2,2,2,2], key = 2, k = 2 | ||
<strong>Output:</strong> [0,1,2,3,4] | ||
<strong>Explanation:</strong> For all indices i in nums, there exists some index j such that |i - j| <= k and nums[j] == key, so every index is a k-distant index. | ||
Hence, we return [0,1,2,3,4]. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 1000</code></li> | ||
<li><code>1 <= nums[i] <= 1000</code></li> | ||
<li><code>key</code> is an integer from the array <code>nums</code>.</li> | ||
<li><code>1 <= k <= nums.length</code></li> | ||
</ul> |
57 changes: 57 additions & 0 deletions
57
Notes/Questions/2201__count-artifacts-that-can-be-extracted/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Problem Statement | ||
|
||
<p>There is an <code>n x n</code> <strong>0-indexed</strong> grid with some artifacts buried in it. You are given the integer <code>n</code> and a <strong>0-indexed </strong>2D integer array <code>artifacts</code> describing the positions of the rectangular artifacts where <code>artifacts[i] = [r1<sub>i</sub>, c1<sub>i</sub>, r2<sub>i</sub>, c2<sub>i</sub>]</code> denotes that the <code>i<sup>th</sup></code> artifact is buried in the subgrid where:</p> | ||
|
||
<ul> | ||
<li><code>(r1<sub>i</sub>, c1<sub>i</sub>)</code> is the coordinate of the <strong>top-left</strong> cell of the <code>i<sup>th</sup></code> artifact and</li> | ||
<li><code>(r2<sub>i</sub>, c2<sub>i</sub>)</code> is the coordinate of the <strong>bottom-right</strong> cell of the <code>i<sup>th</sup></code> artifact.</li> | ||
</ul> | ||
|
||
<p>You will excavate some cells of the grid and remove all the mud from them. If the cell has a part of an artifact buried underneath, it will be uncovered. If all the parts of an artifact are uncovered, you can extract it.</p> | ||
|
||
<p>Given a <strong>0-indexed</strong> 2D integer array <code>dig</code> where <code>dig[i] = [r<sub>i</sub>, c<sub>i</sub>]</code> indicates that you will excavate the cell <code>(r<sub>i</sub>, c<sub>i</sub>)</code>, return <em>the number of artifacts that you can extract</em>.</p> | ||
|
||
<p>The test cases are generated such that:</p> | ||
|
||
<ul> | ||
<li>No two artifacts overlap.</li> | ||
<li>Each artifact only covers at most <code>4</code> cells.</li> | ||
<li>The entries of <code>dig</code> are unique.</li> | ||
</ul> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
<img alt="" src="untitled-diagram.jpg" style="width: 216px; height: 216px;" /> | ||
<pre> | ||
<strong>Input:</strong> n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]] | ||
<strong>Output:</strong> 1 | ||
<strong>Explanation:</strong> | ||
The different colors represent different artifacts. Excavated cells are labeled with a 'D' in the grid. | ||
There is 1 artifact that can be extracted, namely the red artifact. | ||
The blue artifact has one part in cell (1,1) which remains uncovered, so we cannot extract it. | ||
Thus, we return 1. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
<img alt="" src="untitled-diagram-1.jpg" style="width: 216px; height: 216px;" /> | ||
<pre> | ||
<strong>Input:</strong> n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]] | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation:</strong> Both the red and blue artifacts have all parts uncovered (labeled with a 'D') and can be extracted, so we return 2. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= n <= 1000</code></li> | ||
<li><code>1 <= artifacts.length, dig.length <= min(n<sup>2</sup>, 10<sup>5</sup>)</code></li> | ||
<li><code>artifacts[i].length == 4</code></li> | ||
<li><code>dig[i].length == 2</code></li> | ||
<li><code>0 <= r1<sub>i</sub>, c1<sub>i</sub>, r2<sub>i</sub>, c2<sub>i</sub>, r<sub>i</sub>, c<sub>i</sub> <= n - 1</code></li> | ||
<li><code>r1<sub>i</sub> <= r2<sub>i</sub></code></li> | ||
<li><code>c1<sub>i</sub> <= c2<sub>i</sub></code></li> | ||
<li>No two artifacts will overlap.</li> | ||
<li>The number of cells covered by an artifact is <strong>at most</strong> <code>4</code>.</li> | ||
<li>The entries of <code>dig</code> are unique.</li> | ||
</ul> |
Binary file added
BIN
+6.37 KB
Notes/Questions/2201__count-artifacts-that-can-be-extracted/untitled-diagram-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.19 KB
Notes/Questions/2201__count-artifacts-that-can-be-extracted/untitled-diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions
47
Notes/Questions/2202__maximize-the-topmost-element-after-k-moves/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Problem Statement | ||
|
||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the contents of a <b>pile</b>, where <code>nums[0]</code> is the topmost element of the pile.</p> | ||
|
||
<p>In one move, you can perform <strong>either</strong> of the following:</p> | ||
|
||
<ul> | ||
<li>If the pile is not empty, <strong>remove</strong> the topmost element of the pile.</li> | ||
<li>If there are one or more removed elements, <strong>add</strong> any one of them back onto the pile. This element becomes the new topmost element.</li> | ||
</ul> | ||
|
||
<p>You are also given an integer <code>k</code>, which denotes the total number of moves to be made.</p> | ||
|
||
<p>Return <em>the <strong>maximum value</strong> of the topmost element of the pile possible after <strong>exactly</strong></em> <code>k</code> <em>moves</em>. In case it is not possible to obtain a non-empty pile after <code>k</code> moves, return <code>-1</code>.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [5,2,2,4,0,6], k = 4 | ||
<strong>Output:</strong> 5 | ||
<strong>Explanation:</strong> | ||
One of the ways we can end with 5 at the top of the pile after 4 moves is as follows: | ||
- Step 1: Remove the topmost element = 5. The pile becomes [2,2,4,0,6]. | ||
- Step 2: Remove the topmost element = 2. The pile becomes [2,4,0,6]. | ||
- Step 3: Remove the topmost element = 2. The pile becomes [4,0,6]. | ||
- Step 4: Add 5 back onto the pile. The pile becomes [5,4,0,6]. | ||
Note that this is not the only way to end with 5 at the top of the pile. It can be shown that 5 is the largest answer possible after 4 moves. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> nums = [2], k = 1 | ||
<strong>Output:</strong> -1 | ||
<strong>Explanation:</strong> | ||
In the first move, our only option is to pop the topmost element of the pile. | ||
Since it is not possible to obtain a non-empty pile after one move, we return -1. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li> | ||
<li><code>0 <= nums[i], k <= 10<sup>9</sup></code></li> | ||
</ul> |
Binary file added
BIN
+30.9 KB
...ions/2203__minimum-weighted-subgraph-with-the-required-paths/example1drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.46 KB
...ns/2203__minimum-weighted-subgraph-with-the-required-paths/example2-1drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions
46
Notes/Questions/2203__minimum-weighted-subgraph-with-the-required-paths/readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Problem Statement | ||
|
||
<p>You are given an integer <code>n</code> denoting the number of nodes of a <strong>weighted directed</strong> graph. The nodes are numbered from <code>0</code> to <code>n - 1</code>.</p> | ||
|
||
<p>You are also given a 2D integer array <code>edges</code> where <code>edges[i] = [from<sub>i</sub>, to<sub>i</sub>, weight<sub>i</sub>]</code> denotes that there exists a <strong>directed</strong> edge from <code>from<sub>i</sub></code> to <code>to<sub>i</sub></code> with weight <code>weight<sub>i</sub></code>.</p> | ||
|
||
<p>Lastly, you are given three <strong>distinct</strong> integers <code>src1</code>, <code>src2</code>, and <code>dest</code> denoting three distinct nodes of the graph.</p> | ||
|
||
<p>Return <em>the <strong>minimum weight</strong> of a subgraph of the graph such that it is <strong>possible</strong> to reach</em> <code>dest</code> <em>from both</em> <code>src1</code> <em>and</em> <code>src2</code> <em>via a set of edges of this subgraph</em>. In case such a subgraph does not exist, return <code>-1</code>.</p> | ||
|
||
<p>A <strong>subgraph</strong> is a graph whose vertices and edges are subsets of the original graph. The <strong>weight</strong> of a subgraph is the sum of weights of its constituent edges.</p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
<img alt="" src="example1drawio.png" style="width: 263px; height: 250px;" /> | ||
<pre> | ||
<strong>Input:</strong> n = 6, edges = [[0,2,2],[0,5,6],[1,0,3],[1,4,5],[2,1,1],[2,3,3],[2,3,4],[3,4,2],[4,5,1]], src1 = 0, src2 = 1, dest = 5 | ||
<strong>Output:</strong> 9 | ||
<strong>Explanation:</strong> | ||
The above figure represents the input graph. | ||
The blue edges represent one of the subgraphs that yield the optimal answer. | ||
Note that the subgraph [[1,0,3],[0,5,6]] also yields the optimal answer. It is not possible to get a subgraph with less weight satisfying all the constraints. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
<img alt="" src="example2-1drawio.png" style="width: 350px; height: 51px;" /> | ||
<pre> | ||
<strong>Input:</strong> n = 3, edges = [[0,1,1],[2,1,1]], src1 = 0, src2 = 1, dest = 2 | ||
<strong>Output:</strong> -1 | ||
<strong>Explanation:</strong> | ||
The above figure represents the input graph. | ||
It can be seen that there does not exist any path from node 1 to node 2, hence there are no subgraphs satisfying all the constraints. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>3 <= n <= 10<sup>5</sup></code></li> | ||
<li><code>0 <= edges.length <= 10<sup>5</sup></code></li> | ||
<li><code>edges[i].length == 3</code></li> | ||
<li><code>0 <= from<sub>i</sub>, to<sub>i</sub>, src1, src2, dest <= n - 1</code></li> | ||
<li><code>from<sub>i</sub> != to<sub>i</sub></code></li> | ||
<li><code>src1</code>, <code>src2</code>, and <code>dest</code> are pairwise distinct.</li> | ||
<li><code>1 <= weight[i] <= 10<sup>5</sup></code></li> | ||
</ul> |
Oops, something went wrong.