Skip to content

feat: add solutions to weekly contest 412 #3450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 26, 2024
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 solution/0600-0699/0626.Exchange Seats/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tags:
+-------------+---------+
id is the primary key (unique value) column for this table.
Each row of this table indicates the name and the ID of a student.
id is a continuous increment.
The ID sequence always starts from 1 and increments continuously.
</pre>

<p>&nbsp;</p>
Expand Down
2 changes: 2 additions & 0 deletions solution/0600-0699/0690.Employee Importance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public:
};
```

#### Go

```go
/**
* Definition for Employee.
Expand Down
2 changes: 2 additions & 0 deletions solution/0600-0699/0690.Employee Importance/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public:
};
```

#### Go

```go
/**
* Definition for Employee.
Expand Down
36 changes: 21 additions & 15 deletions solution/1000-1099/1052.Grumpy Bookstore Owner/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,38 @@ tags:

<!-- description:start -->

<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>
<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>

<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>
<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>

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

<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>
<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>

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

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

<pre>
<strong>Input:</strong> customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], minutes = 3
<strong>Output:</strong> 16
<strong>Explanation:</strong> The bookstore owner keeps themselves not grumpy for the last 3 minutes.
The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.
</pre>
<div class="example-block">
<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>

<p><strong>Output:</strong> <span class="example-io">16</span></p>

<p><strong>Explanation:</strong></p>

<p>The bookstore owner keeps themselves not grumpy for the last 3 minutes.</p>

<p>The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.</p>
</div>

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

<pre>
<strong>Input:</strong> customers = [1], grumpy = [0], minutes = 1
<strong>Output:</strong> 1
</pre>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">customers = [1], grumpy = [0], minutes = 1</span></p>

<p><strong>Output:</strong> <span class="example-io">1</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ tags:
<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>
</ul>

<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>
<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>

<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>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ tags:

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></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/find_the_city_01.png" style="width: 300px; height: 225px;" />

<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>

<pre>
<strong>Input:</strong> n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4
<strong>Output:</strong> 3
Expand All @@ -42,7 +44,9 @@ Cities 0 and 3 have 2 neighboring cities at a distanceThreshold = 4, but we have
</pre>

<p><strong class="example">Example 2:</strong></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/find_the_city_02.png" style="width: 300px; height: 225px;" />

<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>

<pre>
<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
<strong>Output:</strong> 0
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions solution/1300-1399/1341.Movie Rating/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ title is the name of the movie.
| name | varchar |
+---------------+---------+
user_id is the primary key (column with unique values) for this table.
The column &#39;name&#39; has unique values.
</pre>

<p>&nbsp;</p>

<p>Table: <code>MovieRating</code></p>

<pre>
Expand All @@ -56,7 +55,7 @@ user_id is the primary key (column with unique values) for this table.
| rating | int |
| created_at | date |
+---------------+---------+
(movie_id, user_id) is the primary key (column with unique values)&nbsp;for this table.
(movie_id, user_id) is the primary key (column with unique values) for this table.
This table contains the rating of a movie by a user in their review.
created_at is the user&#39;s review date.
</pre>
Expand Down
4 changes: 2 additions & 2 deletions solution/1400-1499/1462.Course Schedule IV/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ Course 0 is not a prerequisite of course 1, but the opposite is true.
<li><code>2 &lt;= numCourses &lt;= 100</code></li>
<li><code>0 &lt;= prerequisites.length &lt;= (numCourses * (numCourses - 1) / 2)</code></li>
<li><code>prerequisites[i].length == 2</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= n - 1</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= numCourses - 1</code></li>
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
<li>All the pairs <code>[a<sub>i</sub>, b<sub>i</sub>]</code> are <strong>unique</strong>.</li>
<li>The prerequisites graph has no cycles.</li>
<li><code>1 &lt;= queries.length &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= n - 1</code></li>
<li><code>0 &lt;= u<sub>i</sub>, v<sub>i</sub> &lt;= numCourses - 1</code></li>
<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ You can make 8 consecutive integer values starting from 0.</pre>
<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,4,10,3,1]
<strong>Input:</strong> coins = [1,4,10,3,1]
<strong>Output:</strong> 20</pre>

<p>&nbsp;</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : left ?? right;
return left && right ? node : (left ?? right);
};

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

return left && right ? node : left ?? right;
return left && right ? node : (left ?? right);
};

const dfs = (node, x, path) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : left ?? right;
return left && right ? node : (left ?? right);
};

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

return left && right ? node : left ?? right;
return left && right ? node : (left ?? right);
};

const dfs = (node, x, path) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var getDirections = function (root, startValue, destValue) {
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : left ?? right;
return left && right ? node : (left ?? right);
};

const dfs = (node, x, path) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getDirections(root: TreeNode | null, startValue: number, destValue: num
const left = lca(node.left, p, q);
const right = lca(node.right, p, q);

return left && right ? node : left ?? right;
return left && right ? node : (left ?? right);
};

const dfs = (node: TreeNode | null, x: number, path: string[]): boolean => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tags:

<!-- description:start -->

<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>
<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>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ tags:

<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>

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

<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>

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

<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>

<div class="example-block">
<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>
<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>

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

<p><strong>Explanation:</strong></p>

<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>

<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>

<ul>
Expand All @@ -52,15 +52,15 @@ tags:

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

<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>

<div class="example-block">
<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>
<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>

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

<p><strong>Explanation:</strong></p>

<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>

<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>

<ul>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading