Skip to content

Commit e152696

Browse files
authored
feat: add solutions to weekly contest 412 (#3450)
1 parent b0946c3 commit e152696

File tree

47 files changed

+1803
-76
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1803
-76
lines changed

solution/0600-0699/0626.Exchange Seats/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tags:
2727
+-------------+---------+
2828
id is the primary key (unique value) column for this table.
2929
Each row of this table indicates the name and the ID of a student.
30-
id is a continuous increment.
30+
The ID sequence always starts from 1 and increments continuously.
3131
</pre>
3232

3333
<p>&nbsp;</p>

solution/0600-0699/0690.Employee Importance/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public:
172172
};
173173
```
174174
175+
#### Go
176+
175177
```go
176178
/**
177179
* Definition for Employee.

solution/0600-0699/0690.Employee Importance/README_EN.md

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public:
165165
};
166166
```
167167
168+
#### Go
169+
168170
```go
169171
/**
170172
* Definition for Employee.

solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md

+21-15
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,38 @@ tags:
1919

2020
<!-- description:start -->
2121

22-
<p>There is a bookstore owner that has a store open for <code>n</code> minutes. Every minute, some number of customers enter the store. You are given an integer array <code>customers</code> of length <code>n</code> where <code>customers[i]</code> is the number of the customer that enters the store at the start of the <code>i<sup>th</sup></code> minute and all those customers leave after the end of that minute.</p>
22+
<p>There is a bookstore owner that has a store open for <code>n</code> minutes. You are given an integer array <code>customers</code> of length <code>n</code> where <code>customers[i]</code> is the number of the customers that enter the store at the start of the <code>i<sup>th</sup></code> minute and all those customers leave after the end of that minute.</p>
2323

24-
<p>On some minutes, the bookstore owner is grumpy. You are given a binary array grumpy where <code>grumpy[i]</code> is <code>1</code> if the bookstore owner is grumpy during the <code>i<sup>th</sup></code> minute, and is <code>0</code> otherwise.</p>
24+
<p>During certain minutes, the bookstore owner is grumpy. You are given a binary array grumpy where <code>grumpy[i]</code> is <code>1</code> if the bookstore owner is grumpy during the <code>i<sup>th</sup></code> minute, and is <code>0</code> otherwise.</p>
2525

26-
<p>When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise, they are satisfied.</p>
26+
<p>When the bookstore owner is grumpy, the customers entering during that minute are not <strong>satisfied</strong>. Otherwise, they are satisfied.</p>
2727

28-
<p>The bookstore owner knows a secret technique to keep themselves not grumpy for <code>minutes</code> consecutive minutes, but can only use it once.</p>
28+
<p>The bookstore owner knows a secret technique to remain <strong>not grumpy</strong> for <code>minutes</code> consecutive minutes, but this technique can only be used <strong>once</strong>.</p>
2929

30-
<p>Return <em>the maximum number of customers that can be satisfied throughout the day</em>.</p>
30+
<p>Return the <strong>maximum</strong> number of customers that can be <em>satisfied</em> throughout the day.</p>
3131

3232
<p>&nbsp;</p>
3333
<p><strong class="example">Example 1:</strong></p>
3434

35-
<pre>
36-
<strong>Input:</strong> customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
37-
<strong>Output:</strong> 16
38-
<strong>Explanation:</strong> The bookstore owner keeps themselves not grumpy for the last 3 minutes.
39-
The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
40-
</pre>
35+
<div class="example-block">
36+
<p><strong>Input:</strong> <span class="example-io">customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3</span></p>
37+
38+
<p><strong>Output:</strong> <span class="example-io">16</span></p>
39+
40+
<p><strong>Explanation:</strong></p>
41+
42+
<p>The bookstore owner keeps themselves not grumpy for the last 3 minutes.</p>
43+
44+
<p>The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.</p>
45+
</div>
4146

4247
<p><strong class="example">Example 2:</strong></p>
4348

44-
<pre>
45-
<strong>Input:</strong> customers = [1], grumpy = [0], minutes = 1
46-
<strong>Output:</strong> 1
47-
</pre>
49+
<div class="example-block">
50+
<p><strong>Input:</strong> <span class="example-io">customers = [1], grumpy = [0], minutes = 1</span></p>
51+
52+
<p><strong>Output:</strong> <span class="example-io">1</span></p>
53+
</div>
4854

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

solution/1100-1199/1152.Analyze User Website Visit Pattern/README_EN.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ tags:
3636
<li>Also, if the pattern is <code>[&quot;luffy&quot;, &quot;luffy&quot;, &quot;luffy&quot;]</code>, the score is the number of users <code>x</code> such that <code>x</code> visited <code>&quot;luffy&quot;</code> three different times at different timestamps.</li>
3737
</ul>
3838

39-
<p>Return <em>the <strong>pattern</strong> with the largest <strong>score</strong></em>. If there is more than one pattern with the same largest score, return the lexicographically smallest such pattern.</p>
39+
<p>Return the <strong>pattern</strong> with the largest <strong>score</strong>. If there is more than one pattern with the same largest score, return the lexicographically smallest such pattern.</p>
40+
41+
<p>Note that the websites in a pattern <strong>do not</strong> need to be visited <em>contiguously</em>, they only need to be visited in the order they appeared in the pattern.</p>
4042

4143
<p>&nbsp;</p>
4244
<p><strong class="example">Example 1:</strong></p>

solution/1300-1399/1334.Find the City With the Smallest Number of Neighbors at a Threshold Distance/README_EN.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ tags:
2828

2929
<p>&nbsp;</p>
3030
<p><strong class="example">Example 1:</strong></p>
31-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/images/find_the_city_01.png" style="width: 300px; height: 225px;" />
31+
32+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/images/problem1334example1.png" style="width: 300px; height: 224px;" /></p>
33+
3234
<pre>
3335
<strong>Input:</strong> n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4
3436
<strong>Output:</strong> 3
@@ -42,7 +44,9 @@ Cities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have
4244
</pre>
4345

4446
<p><strong class="example">Example 2:</strong></p>
45-
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/images/find_the_city_02.png" style="width: 300px; height: 225px;" />
47+
48+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1300-1399/1334.Find%20the%20City%20With%20the%20Smallest%20Number%20of%20Neighbors%20at%20a%20Threshold%20Distance/images/problem1334example0.png" style="width: 300px; height: 224px;" /></p>
49+
4650
<pre>
4751
<strong>Input:</strong> n = 5, edges = [[0,1,2],[0,4,8],[1,2,3],[1,4,2],[2,3,1],[3,4,1]], distanceThreshold = 2
4852
<strong>Output:</strong> 0

solution/1300-1399/1341.Movie Rating/README_EN.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ title is the name of the movie.
4141
| name | varchar |
4242
+---------------+---------+
4343
user_id is the primary key (column with unique values) for this table.
44+
The column &#39;name&#39; has unique values.
4445
</pre>
4546

46-
<p>&nbsp;</p>
47-
4847
<p>Table: <code>MovieRating</code></p>
4948

5049
<pre>
@@ -56,7 +55,7 @@ user_id is the primary key (column with unique values) for this table.
5655
| rating | int |
5756
| created_at | date |
5857
+---------------+---------+
59-
(movie_id, user_id) is the primary key (column with unique values)&nbsp;for this table.
58+
(movie_id, user_id) is the primary key (column with unique values) for this table.
6059
This table contains the rating of a movie by a user in their review.
6160
created_at is the user&#39;s review date.
6261
</pre>

solution/1400-1499/1462.Course Schedule IV/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ Course 0 is not a prerequisite of course 1, but the opposite is true.
6565
<li><code>2 &lt;= numCourses &lt;= 100</code></li>
6666
<li><code>0 &lt;= prerequisites.length &lt;= (numCourses * (numCourses - 1) / 2)</code></li>
6767
<li><code>prerequisites[i].length == 2</code></li>
68-
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= n - 1</code></li>
68+
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= numCourses - 1</code></li>
6969
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
7070
<li>All the pairs <code>[a<sub>i</sub>, b<sub>i</sub>]</code> are <strong>unique</strong>.</li>
7171
<li>The prerequisites graph has no cycles.</li>
7272
<li><code>1 &lt;= queries.length &lt;= 10<sup>4</sup></code></li>
73-
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= n - 1</code></li>
73+
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= numCourses - 1</code></li>
7474
<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>
7575
</ul>
7676

solution/1700-1799/1798.Maximum Number of Consecutive Values You Can Make/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ You can make 8 consecutive integer values starting from 0.</pre>
5656
<p><strong class="example">Example 3:</strong></p>
5757

5858
<pre>
59-
<strong>Input:</strong> nums = [1,4,10,3,1]
59+
<strong>Input:</strong> coins = [1,4,10,3,1]
6060
<strong>Output:</strong> 20</pre>
6161

6262
<p>&nbsp;</p>

solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
314314
const left = lca(node.left, p, q);
315315
const right = lca(node.right, p, q);
316316

317-
return left && right ? node : left ?? right;
317+
return left && right ? node : (left ?? right);
318318
};
319319

320320
const dfs = (node: TreeNode | null, x: number, path: string[]): boolean => {
@@ -370,7 +370,7 @@ var getDirections = function (root, startValue, destValue) {
370370
const left = lca(node.left, p, q);
371371
const right = lca(node.right, p, q);
372372

373-
return left && right ? node : left ?? right;
373+
return left && right ? node : (left ?? right);
374374
};
375375

376376
const dfs = (node, x, path) => {

solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
310310
const left = lca(node.left, p, q);
311311
const right = lca(node.right, p, q);
312312

313-
return left && right ? node : left ?? right;
313+
return left && right ? node : (left ?? right);
314314
};
315315

316316
const dfs = (node: TreeNode | null, x: number, path: string[]): boolean => {
@@ -366,7 +366,7 @@ var getDirections = function (root, startValue, destValue) {
366366
const left = lca(node.left, p, q);
367367
const right = lca(node.right, p, q);
368368

369-
return left && right ? node : left ?? right;
369+
return left && right ? node : (left ?? right);
370370
};
371371

372372
const dfs = (node, x, path) => {

solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/Solution.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var getDirections = function (root, startValue, destValue) {
2020
const left = lca(node.left, p, q);
2121
const right = lca(node.right, p, q);
2222

23-
return left && right ? node : left ?? right;
23+
return left && right ? node : (left ?? right);
2424
};
2525

2626
const dfs = (node, x, path) => {

solution/2000-2099/2096.Step-By-Step Directions From a Binary Tree Node to Another/Solution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
2020
const left = lca(node.left, p, q);
2121
const right = lca(node.right, p, q);
2222

23-
return left && right ? node : left ?? right;
23+
return left && right ? node : (left ?? right);
2424
};
2525

2626
const dfs = (node: TreeNode | null, x: number, path: string[]): boolean => {

solution/3100-3199/3102.Minimize Manhattan Distances/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tags:
2222

2323
<!-- description:start -->
2424

25-
<p>You are given a array <code>points</code> representing integer coordinates of some points on a 2D plane, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.</p>
25+
<p>You are given an array <code>points</code> representing integer coordinates of some points on a 2D plane, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.</p>
2626

2727
<p>The distance between two points is defined as their <span data-keyword="manhattan-distance">Manhattan distance</span>.</p>
2828

solution/3100-3199/3112.Minimum Time to Visit Disappearing Nodes/README_EN.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ tags:
2525

2626
<p>Additionally, you are given an array <code>disappear</code>, where <code>disappear[i]</code> denotes the time when the node <code>i</code> disappears from the graph and you won&#39;t be able to visit it.</p>
2727

28-
<p><strong>Notice</strong> that the graph might be disconnected and might contain multiple edges.</p>
28+
<p><strong>Note</strong>&nbsp;that the graph might be <em>disconnected</em> and might contain <em>multiple edges</em>.</p>
2929

3030
<p>Return the array <code>answer</code>, with <code>answer[i]</code> denoting the <strong>minimum</strong> units of time required to reach node <code>i</code> from node 0. If node <code>i</code> is <strong>unreachable</strong> from node 0 then <code>answer[i]</code> is <code>-1</code>.</p>
3131

3232
<p>&nbsp;</p>
3333
<p><strong class="example">Example 1:</strong></p>
3434

35-
<p><img 10px="" alt="" padding:="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3100-3199/3112.Minimum%20Time%20to%20Visit%20Disappearing%20Nodes/images/example1.png" style="width: 350px; height: 210px;" /></p>
36-
3735
<div class="example-block">
38-
<p><strong>Input:</strong> <span class="example-io"> n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5]</span></p>
36+
<p><strong>Input:</strong> <span class="example-io">n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,1,5]</span></p>
3937

40-
<p><strong>Output:</strong> <span class="example-io"> [0,-1,4]</span></p>
38+
<p><strong>Output:</strong> <span class="example-io">[0,-1,4]</span></p>
4139

4240
<p><strong>Explanation:</strong></p>
4341

42+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3100-3199/3112.Minimum%20Time%20to%20Visit%20Disappearing%20Nodes/images/output-onlinepngtools.png" style="width: 350px; height: 210px;" /></p>
43+
4444
<p>We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.</p>
4545

4646
<ul>
@@ -52,15 +52,15 @@ tags:
5252

5353
<p><strong class="example">Example 2:</strong></p>
5454

55-
<p><img 10px="" alt="" padding:="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3100-3199/3112.Minimum%20Time%20to%20Visit%20Disappearing%20Nodes/images/example2.png" style="width: 350px; height: 210px;" /></p>
56-
5755
<div class="example-block">
58-
<p><strong>Input:</strong> <span class="example-io"> n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5]</span></p>
56+
<p><strong>Input:</strong> <span class="example-io">n = 3, edges = [[0,1,2],[1,2,1],[0,2,4]], disappear = [1,3,5]</span></p>
5957

60-
<p><strong>Output:</strong> <span class="example-io"> [0,2,3]</span></p>
58+
<p><strong>Output:</strong> <span class="example-io">[0,2,3]</span></p>
6159

6260
<p><strong>Explanation:</strong></p>
6361

62+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3100-3199/3112.Minimum%20Time%20to%20Visit%20Disappearing%20Nodes/images/output-onlinepngtools-1.png" style="width: 350px; height: 210px;" /></p>
63+
6464
<p>We are starting our journey from node 0, and our goal is to find the minimum time required to reach each node before it disappears.</p>
6565

6666
<ul>

0 commit comments

Comments
 (0)