Skip to content
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

feat: add weekly contest 430 #3900

Merged
merged 2 commits into from
Dec 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tags:

<pre>
<strong>输入: </strong>s = "abcabcbb"
<strong>输出: </strong>3
<strong>输出: </strong>3
<strong>解释:</strong> 因为无重复字符的最长子串是 <code>"abc"</code>,所以其长度为 3。
</pre>

Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0189.Rotate Array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tags:
<pre>
<strong>输入:</strong>nums = [-1,-100,3,99], k = 2
<strong>输出:</strong>[3,99,-1,-100]
<strong>解释:</strong>
<strong>解释:</strong>
向右轮转 1 步: [99,-1,-100,3]
向右轮转 2 步: [3,99,-1,-100]</pre>

Expand Down
2 changes: 1 addition & 1 deletion solution/0100-0199/0189.Rotate Array/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rotate 3 steps to the right: [5,6,7,1,2,3,4]
<pre>
<strong>Input:</strong> nums = [-1,-100,3,99], k = 2
<strong>Output:</strong> [3,99,-1,-100]
<strong>Explanation:</strong>
<strong>Explanation:</strong>
rotate 1 steps to the right: [99,-1,-100,3]
rotate 2 steps to the right: [3,99,-1,-100]
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tags:
<pre>
<strong>Input:</strong> nums = [1,3,-1,-3,5,3,6,7], k = 3
<strong>Output:</strong> [3,3,5,5,6,7]
<strong>Explanation:</strong>
<strong>Explanation:</strong>
Window position Max
--------------- -----
[1 3 -1] -3 5 3 6 7 <strong>3</strong>
Expand Down
2 changes: 1 addition & 1 deletion solution/1300-1399/1366.Rank Teams by Votes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ C 队获得三票「排位第二」,两票「排位第三」。
<strong>输入:</strong>votes = ["WXYZ","XYZW"]
<strong>输出:</strong>"XWYZ"
<strong>解释:</strong>
X 队在并列僵局打破后成为排名第一的团队。X 队和 W 队的「排位第一」票数一样,但是 X 队有一票「排位第二」,而 W 没有获得「排位第二」。
X 队在并列僵局打破后成为排名第一的团队。X 队和 W 队的「排位第一」票数一样,但是 X 队有一票「排位第二」,而 W 没有获得「排位第二」。
</pre>

<p><strong class="example">示例 3:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/1300-1399/1366.Rank Teams by Votes/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tags:
<pre>
<strong>Input:</strong> votes = [&quot;ABC&quot;,&quot;ACB&quot;,&quot;ABC&quot;,&quot;ACB&quot;,&quot;ACB&quot;]
<strong>Output:</strong> &quot;ACB&quot;
<strong>Explanation:</strong>
<strong>Explanation:</strong>
Team A was ranked first place by 5 voters. No other team was voted as first place, so team A is the first team.
Team B was ranked second by 2 voters and ranked third by 3 voters.
Team C was ranked second by 3 voters and ranked third by 2 voters.
Expand All @@ -49,7 +49,7 @@ As most of the voters ranked C second, team C is the second team, and team B is
<strong>Input:</strong> votes = [&quot;WXYZ&quot;,&quot;XYZW&quot;]
<strong>Output:</strong> &quot;XWYZ&quot;
<strong>Explanation:</strong>
X is the winner due to the tie-breaking rule. X has the same votes as W for the first position, but X has one vote in the second position, while W does not have any votes in the second position.
X is the winner due to the tie-breaking rule. X has the same votes as W for the first position, but X has one vote in the second position, while W does not have any votes in the second position.
</pre>

<p><strong class="example">Example 3:</strong></p>
Expand Down
120 changes: 120 additions & 0 deletions solution/3400-3499/3401.Find Circular Gift Exchange Chains/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README.md
tags:
- 数据库
---

<!-- problem:start -->

# [3401. Find Circular Gift Exchange Chains 🔒](https://leetcode.cn/problems/find-circular-gift-exchange-chains)

[English Version](/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README_EN.md)

## 题目描述

<!-- description:start -->

<p>Table: <code>SecretSanta</code></p>

<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| giver_id | int |
| receiver_id | int |
| gift_value | int |
+-------------+------+
(giver_id, receiver_id) is the unique key for this table.
Each row represents a record of a gift exchange between two employees, giver_id represents the employee who gives a gift, receiver_id represents the employee who receives the gift and gift_value represents the value of the gift given.
</pre>

<p>Write a solution to find the <strong>total gift value</strong> and <strong>length</strong> of<strong> circular chains</strong> of Secret Santa gift exchanges:</p>

<p>A <strong>circular chain</strong> is defined as a series of exchanges where:</p>

<ul>
<li>Each employee gives a gift to <strong>exactly one</strong> other employee.</li>
<li>Each employee receives a gift <strong>from exactly</strong> one other employee.</li>
<li>The exchanges form a continuous <strong>loop</strong> (e.g., employee A gives a gift to B, B gives to C, and C gives back to A).</li>
</ul>

<p>Return <em>the result ordered by the chain length and total gift value of the chain in&nbsp;<strong>descending</strong> order</em>.&nbsp;</p>

<p>The result format is in the following example.</p>

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

<div class="example-block">
<p><strong>Input:</strong></p>

<p>SecretSanta table:</p>

<pre class="example-io">
+----------+-------------+------------+
| giver_id | receiver_id | gift_value |
+----------+-------------+------------+
| 1 | 2 | 20 |
| 2 | 3 | 30 |
| 3 | 1 | 40 |
| 4 | 5 | 25 |
| 5 | 4 | 35 |
+----------+-------------+------------+
</pre>

<p><strong>Output:</strong></p>

<pre class="example-io">
+----------+--------------+------------------+
| chain_id | chain_length | total_gift_value |
+----------+--------------+------------------+
| 1 | 3 | 90 |
| 2 | 2 | 60 |
+----------+--------------+------------------+
</pre>

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

<ul>
<li><strong>Chain 1</strong> involves employees 1, 2, and 3:

<ul>
<li>Employee 1 gives a gift to 2, employee 2 gives a gift to 3, and employee 3 gives a gift to 1.</li>
<li>Total gift value for this chain = 20 + 30 + 40 = 90.</li>
</ul>
</li>
<li><strong>Chain 2</strong> involves employees 4 and 5:
<ul>
<li>Employee 4 gives a gift to 5, and employee 5 gives a gift to 4.</li>
<li>Total gift value for this chain = 25 + 35 = 60.</li>
</ul>
</li>

</ul>

<p>The result table is ordered by the chain length and total gift value of the chain in descending order.</p>
</div>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### MySQL

```sql

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README_EN.md
tags:
- Database
---

<!-- problem:start -->

# [3401. Find Circular Gift Exchange Chains 🔒](https://leetcode.com/problems/find-circular-gift-exchange-chains)

[中文文档](/solution/3400-3499/3401.Find%20Circular%20Gift%20Exchange%20Chains/README.md)

## Description

<!-- description:start -->

<p>Table: <code>SecretSanta</code></p>

<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| giver_id | int |
| receiver_id | int |
| gift_value | int |
+-------------+------+
(giver_id, receiver_id) is the unique key for this table.
Each row represents a record of a gift exchange between two employees, giver_id represents the employee who gives a gift, receiver_id represents the employee who receives the gift and gift_value represents the value of the gift given.
</pre>

<p>Write a solution to find the <strong>total gift value</strong> and <strong>length</strong> of<strong> circular chains</strong> of Secret Santa gift exchanges:</p>

<p>A <strong>circular chain</strong> is defined as a series of exchanges where:</p>

<ul>
<li>Each employee gives a gift to <strong>exactly one</strong> other employee.</li>
<li>Each employee receives a gift <strong>from exactly</strong> one other employee.</li>
<li>The exchanges form a continuous <strong>loop</strong> (e.g., employee A gives a gift to B, B gives to C, and C gives back to A).</li>
</ul>

<p>Return <em>the result ordered by the chain length and total gift value of the chain in&nbsp;<strong>descending</strong> order</em>.&nbsp;</p>

<p>The result format is in the following example.</p>

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

<div class="example-block">
<p><strong>Input:</strong></p>

<p>SecretSanta table:</p>

<pre class="example-io">
+----------+-------------+------------+
| giver_id | receiver_id | gift_value |
+----------+-------------+------------+
| 1 | 2 | 20 |
| 2 | 3 | 30 |
| 3 | 1 | 40 |
| 4 | 5 | 25 |
| 5 | 4 | 35 |
+----------+-------------+------------+
</pre>

<p><strong>Output:</strong></p>

<pre class="example-io">
+----------+--------------+------------------+
| chain_id | chain_length | total_gift_value |
+----------+--------------+------------------+
| 1 | 3 | 90 |
| 2 | 2 | 60 |
+----------+--------------+------------------+
</pre>

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

<ul>
<li><strong>Chain 1</strong> involves employees 1, 2, and 3:

<ul>
<li>Employee 1 gives a gift to 2, employee 2 gives a gift to 3, and employee 3 gives a gift to 1.</li>
<li>Total gift value for this chain = 20 + 30 + 40 = 90.</li>
</ul>
</li>
<li><strong>Chain 2</strong> involves employees 4 and 5:
<ul>
<li>Employee 4 gives a gift to 5, and employee 5 gives a gift to 4.</li>
<li>Total gift value for this chain = 25 + 35 = 60.</li>
</ul>
</li>

</ul>

<p>The result table is ordered by the chain length and total gift value of the chain in descending order.</p>
</div>

<!-- description:end -->

## Solutions

<!-- solution:start -->

### Solution 1

<!-- tabs:start -->

#### MySQL

```sql

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading
Loading