diff --git a/solution/3300-3399/3388.Count Beautiful Splits in an Array/Solution.cpp b/solution/3300-3399/3388.Count Beautiful Splits in an Array/Solution.cpp
index d700db0defcbb..3ecd74e6df21a 100644
--- a/solution/3300-3399/3388.Count Beautiful Splits in an Array/Solution.cpp
+++ b/solution/3300-3399/3388.Count Beautiful Splits in an Array/Solution.cpp
@@ -11,7 +11,7 @@ class Solution {
}
}
}
-
+
int ans = 0;
for (int i = 1; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
diff --git a/solution/3300-3399/3390.Longest Team Pass Streak/README.md b/solution/3300-3399/3390.Longest Team Pass Streak/README.md
new file mode 100644
index 0000000000000..5d235505686d8
--- /dev/null
+++ b/solution/3300-3399/3390.Longest Team Pass Streak/README.md
@@ -0,0 +1,211 @@
+---
+comments: true
+difficulty: 困难
+edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README.md
+tags:
+ - 数据库
+---
+
+
+
+# [3390. Longest Team Pass Streak 🔒](https://leetcode.cn/problems/longest-team-pass-streak)
+
+[English Version](/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README_EN.md)
+
+## 题目描述
+
+
+
+
Table: Teams
+
+
++-------------+---------+
+| Column Name | Type |
++-------------+---------+
+| player_id | int |
+| team_name | varchar |
++-------------+---------+
+player_id is the unique key for this table.
+Each row contains the unique identifier for player and the name of one of the teams participating in that match.
+
+
+Table: Passes
+
+
++-------------+---------+
+| Column Name | Type |
++-------------+---------+
+| pass_from | int |
+| time_stamp | varchar |
+| pass_to | int |
++-------------+---------+
+(pass_from, time_stamp) is the unique key for this table.
+pass_from is a foreign key to player_id from Teams table.
+Each row represents a pass made during a match, time_stamp represents the time in minutes (00:00-90:00) when the pass was made,
+pass_to is the player_id of the player receiving the pass.
+
+
+Write a solution to find the longest successful pass streak for each team during the match. The rules are as follows:
+
+
+ - A successful pass streak is defined as consecutive passes where:
+
+ - Both the
pass_from
and pass_to
players belong to the same team
+
+
+ - A streak breaks when either:
+
+ - The pass is intercepted (received by a player from the opposing team)
+
+
+
+
+Return the result table ordered by team_name
in ascending order.
+
+The result format is in the following example.
+
+
+Example:
+
+
+
Input:
+
+
Teams table:
+
+
++-----------+-----------+
+| player_id | team_name |
++-----------+-----------+
+| 1 | Arsenal |
+| 2 | Arsenal |
+| 3 | Arsenal |
+| 4 | Arsenal |
+| 5 | Chelsea |
+| 6 | Chelsea |
+| 7 | Chelsea |
+| 8 | Chelsea |
++-----------+-----------+
+
+
+
Passes table:
+
+
++-----------+------------+---------+
+| pass_from | time_stamp | pass_to |
++-----------+------------+---------+
+| 1 | 00:05 | 2 |
+| 2 | 00:07 | 3 |
+| 3 | 00:08 | 4 |
+| 4 | 00:10 | 5 |
+| 6 | 00:15 | 7 |
+| 7 | 00:17 | 8 |
+| 8 | 00:20 | 6 |
+| 6 | 00:22 | 5 |
+| 1 | 00:25 | 2 |
+| 2 | 00:27 | 3 |
++-----------+------------+---------+
+
+
+
Output:
+
+
++-----------+----------------+
+| team_name | longest_streak |
++-----------+----------------+
+| Arsenal | 3 |
+| Chelsea | 4 |
++-----------+----------------+
+
+
+
Explanation:
+
+
+ - Arsenal's streaks:
+
+
+ - First streak: 3 passes (1→2→3→4) ended when player 4 passed to Chelsea's player 5
+ - Second streak: 2 passes (1→2→3)
+ - Longest streak = 3
+
+
+ - Chelsea's streaks:
+
+ - First streak: 3 passes (6→7→8→6→5)
+ - Longest streak = 4
+
+
+
+
+
+
+
+
+## 解法
+
+
+
+### 方法一
+
+
+
+#### MySQL
+
+```sql
+WITH
+ PassesWithTeams AS (
+ SELECT
+ p.pass_from,
+ p.pass_to,
+ t1.team_name AS team_from,
+ t2.team_name AS team_to,
+ IF(t1.team_name = t2.team_name, 1, 0) same_team_flag,
+ p.time_stamp
+ FROM
+ Passes p
+ JOIN Teams t1 ON p.pass_from = t1.player_id
+ JOIN Teams t2 ON p.pass_to = t2.player_id
+ ),
+ StreakGroups AS (
+ SELECT
+ team_from AS team_name,
+ time_stamp,
+ same_team_flag,
+ SUM(
+ CASE
+ WHEN same_team_flag = 0 THEN 1
+ ELSE 0
+ END
+ ) OVER (
+ PARTITION BY team_from
+ ORDER BY time_stamp
+ ) AS group_id
+ FROM PassesWithTeams
+ ),
+ StreakLengths AS (
+ SELECT
+ team_name,
+ group_id,
+ COUNT(*) AS streak_length
+ FROM StreakGroups
+ WHERE same_team_flag = 1
+ GROUP BY 1, 2
+ ),
+ LongestStreaks AS (
+ SELECT
+ team_name,
+ MAX(streak_length) AS longest_streak
+ FROM StreakLengths
+ GROUP BY 1
+ )
+SELECT
+ team_name,
+ longest_streak
+FROM LongestStreaks
+ORDER BY 1;
+```
+
+
+
+
+
+
diff --git a/solution/3300-3399/3390.Longest Team Pass Streak/README_EN.md b/solution/3300-3399/3390.Longest Team Pass Streak/README_EN.md
new file mode 100644
index 0000000000000..8581bf40c76bb
--- /dev/null
+++ b/solution/3300-3399/3390.Longest Team Pass Streak/README_EN.md
@@ -0,0 +1,211 @@
+---
+comments: true
+difficulty: Hard
+edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README_EN.md
+tags:
+ - Database
+---
+
+
+
+# [3390. Longest Team Pass Streak 🔒](https://leetcode.com/problems/longest-team-pass-streak)
+
+[中文文档](/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README.md)
+
+## Description
+
+
+
+Table: Teams
+
+
++-------------+---------+
+| Column Name | Type |
++-------------+---------+
+| player_id | int |
+| team_name | varchar |
++-------------+---------+
+player_id is the unique key for this table.
+Each row contains the unique identifier for player and the name of one of the teams participating in that match.
+
+
+Table: Passes
+
+
++-------------+---------+
+| Column Name | Type |
++-------------+---------+
+| pass_from | int |
+| time_stamp | varchar |
+| pass_to | int |
++-------------+---------+
+(pass_from, time_stamp) is the unique key for this table.
+pass_from is a foreign key to player_id from Teams table.
+Each row represents a pass made during a match, time_stamp represents the time in minutes (00:00-90:00) when the pass was made,
+pass_to is the player_id of the player receiving the pass.
+
+
+Write a solution to find the longest successful pass streak for each team during the match. The rules are as follows:
+
+
+ - A successful pass streak is defined as consecutive passes where:
+
+ - Both the
pass_from
and pass_to
players belong to the same team
+
+
+ - A streak breaks when either:
+
+ - The pass is intercepted (received by a player from the opposing team)
+
+
+
+
+Return the result table ordered by team_name
in ascending order.
+
+The result format is in the following example.
+
+
+Example:
+
+
+
Input:
+
+
Teams table:
+
+
++-----------+-----------+
+| player_id | team_name |
++-----------+-----------+
+| 1 | Arsenal |
+| 2 | Arsenal |
+| 3 | Arsenal |
+| 4 | Arsenal |
+| 5 | Chelsea |
+| 6 | Chelsea |
+| 7 | Chelsea |
+| 8 | Chelsea |
++-----------+-----------+
+
+
+
Passes table:
+
+
++-----------+------------+---------+
+| pass_from | time_stamp | pass_to |
++-----------+------------+---------+
+| 1 | 00:05 | 2 |
+| 2 | 00:07 | 3 |
+| 3 | 00:08 | 4 |
+| 4 | 00:10 | 5 |
+| 6 | 00:15 | 7 |
+| 7 | 00:17 | 8 |
+| 8 | 00:20 | 6 |
+| 6 | 00:22 | 5 |
+| 1 | 00:25 | 2 |
+| 2 | 00:27 | 3 |
++-----------+------------+---------+
+
+
+
Output:
+
+
++-----------+----------------+
+| team_name | longest_streak |
++-----------+----------------+
+| Arsenal | 3 |
+| Chelsea | 4 |
++-----------+----------------+
+
+
+
Explanation:
+
+
+ - Arsenal's streaks:
+
+
+ - First streak: 3 passes (1→2→3→4) ended when player 4 passed to Chelsea's player 5
+ - Second streak: 2 passes (1→2→3)
+ - Longest streak = 3
+
+
+ - Chelsea's streaks:
+
+ - First streak: 3 passes (6→7→8→6→5)
+ - Longest streak = 4
+
+
+
+
+
+
+
+
+## Solutions
+
+
+
+### Solution 1
+
+
+
+#### MySQL
+
+```sql
+WITH
+ PassesWithTeams AS (
+ SELECT
+ p.pass_from,
+ p.pass_to,
+ t1.team_name AS team_from,
+ t2.team_name AS team_to,
+ IF(t1.team_name = t2.team_name, 1, 0) same_team_flag,
+ p.time_stamp
+ FROM
+ Passes p
+ JOIN Teams t1 ON p.pass_from = t1.player_id
+ JOIN Teams t2 ON p.pass_to = t2.player_id
+ ),
+ StreakGroups AS (
+ SELECT
+ team_from AS team_name,
+ time_stamp,
+ same_team_flag,
+ SUM(
+ CASE
+ WHEN same_team_flag = 0 THEN 1
+ ELSE 0
+ END
+ ) OVER (
+ PARTITION BY team_from
+ ORDER BY time_stamp
+ ) AS group_id
+ FROM PassesWithTeams
+ ),
+ StreakLengths AS (
+ SELECT
+ team_name,
+ group_id,
+ COUNT(*) AS streak_length
+ FROM StreakGroups
+ WHERE same_team_flag = 1
+ GROUP BY 1, 2
+ ),
+ LongestStreaks AS (
+ SELECT
+ team_name,
+ MAX(streak_length) AS longest_streak
+ FROM StreakLengths
+ GROUP BY 1
+ )
+SELECT
+ team_name,
+ longest_streak
+FROM LongestStreaks
+ORDER BY 1;
+```
+
+
+
+
+
+
diff --git a/solution/3300-3399/3390.Longest Team Pass Streak/Solution.sql b/solution/3300-3399/3390.Longest Team Pass Streak/Solution.sql
new file mode 100644
index 0000000000000..8f8ff1cb41cc2
--- /dev/null
+++ b/solution/3300-3399/3390.Longest Team Pass Streak/Solution.sql
@@ -0,0 +1,51 @@
+WITH
+ PassesWithTeams AS (
+ SELECT
+ p.pass_from,
+ p.pass_to,
+ t1.team_name AS team_from,
+ t2.team_name AS team_to,
+ IF(t1.team_name = t2.team_name, 1, 0) same_team_flag,
+ p.time_stamp
+ FROM
+ Passes p
+ JOIN Teams t1 ON p.pass_from = t1.player_id
+ JOIN Teams t2 ON p.pass_to = t2.player_id
+ ),
+ StreakGroups AS (
+ SELECT
+ team_from AS team_name,
+ time_stamp,
+ same_team_flag,
+ SUM(
+ CASE
+ WHEN same_team_flag = 0 THEN 1
+ ELSE 0
+ END
+ ) OVER (
+ PARTITION BY team_from
+ ORDER BY time_stamp
+ ) AS group_id
+ FROM PassesWithTeams
+ ),
+ StreakLengths AS (
+ SELECT
+ team_name,
+ group_id,
+ COUNT(*) AS streak_length
+ FROM StreakGroups
+ WHERE same_team_flag = 1
+ GROUP BY 1, 2
+ ),
+ LongestStreaks AS (
+ SELECT
+ team_name,
+ MAX(streak_length) AS longest_streak
+ FROM StreakLengths
+ GROUP BY 1
+ )
+SELECT
+ team_name,
+ longest_streak
+FROM LongestStreaks
+ORDER BY 1;
diff --git a/solution/DATABASE_README.md b/solution/DATABASE_README.md
index 7faa9369b165a..5e0dfeed41cb4 100644
--- a/solution/DATABASE_README.md
+++ b/solution/DATABASE_README.md
@@ -304,6 +304,7 @@
| 3368 | [首字母大写](/solution/3300-3399/3368.First%20Letter%20Capitalization/README.md) | `数据库` | 困难 | 🔒 |
| 3374 | [首字母大写 II](/solution/3300-3399/3374.First%20Letter%20Capitalization%20II/README.md) | `数据库` | 困难 | |
| 3384 | [球队传球成功的优势得分](/solution/3300-3399/3384.Team%20Dominance%20by%20Pass%20Success/README.md) | `数据库` | 困难 | 🔒 |
+| 3390 | [Longest Team Pass Streak](/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README.md) | | 困难 | 🔒 |
## 版权
diff --git a/solution/DATABASE_README_EN.md b/solution/DATABASE_README_EN.md
index 12c86a8ce697f..a400f0bc068d8 100644
--- a/solution/DATABASE_README_EN.md
+++ b/solution/DATABASE_README_EN.md
@@ -302,6 +302,7 @@ Press Control + F(or Command + F on
| 3368 | [First Letter Capitalization](/solution/3300-3399/3368.First%20Letter%20Capitalization/README_EN.md) | `Database` | Hard | 🔒 |
| 3374 | [First Letter Capitalization II](/solution/3300-3399/3374.First%20Letter%20Capitalization%20II/README_EN.md) | `Database` | Hard | |
| 3384 | [Team Dominance by Pass Success](/solution/3300-3399/3384.Team%20Dominance%20by%20Pass%20Success/README_EN.md) | `Database` | Hard | 🔒 |
+| 3390 | [Longest Team Pass Streak](/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README_EN.md) | | Hard | 🔒 |
## Copyright
diff --git a/solution/README.md b/solution/README.md
index 485588b9ada76..2339e7fc55718 100644
--- a/solution/README.md
+++ b/solution/README.md
@@ -3400,6 +3400,7 @@
| 3387 | [两天自由外汇交易后的最大货币数](/solution/3300-3399/3387.Maximize%20Amount%20After%20Two%20Days%20of%20Conversions/README.md) | | 中等 | 第 428 场周赛 |
| 3388 | [统计数组中的美丽分割](/solution/3300-3399/3388.Count%20Beautiful%20Splits%20in%20an%20Array/README.md) | | 中等 | 第 428 场周赛 |
| 3389 | [使字符频率相等的最少操作次数](/solution/3300-3399/3389.Minimum%20Operations%20to%20Make%20Character%20Frequencies%20Equal/README.md) | | 困难 | 第 428 场周赛 |
+| 3390 | [Longest Team Pass Streak](/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README.md) | | 困难 | 🔒 |
## 版权
diff --git a/solution/README_EN.md b/solution/README_EN.md
index 61f68b892b1c5..0d7bd34be9b51 100644
--- a/solution/README_EN.md
+++ b/solution/README_EN.md
@@ -3398,6 +3398,7 @@ Press Control + F(or Command + F on
| 3387 | [Maximize Amount After Two Days of Conversions](/solution/3300-3399/3387.Maximize%20Amount%20After%20Two%20Days%20of%20Conversions/README_EN.md) | | Medium | Weekly Contest 428 |
| 3388 | [Count Beautiful Splits in an Array](/solution/3300-3399/3388.Count%20Beautiful%20Splits%20in%20an%20Array/README_EN.md) | | Medium | Weekly Contest 428 |
| 3389 | [Minimum Operations to Make Character Frequencies Equal](/solution/3300-3399/3389.Minimum%20Operations%20to%20Make%20Character%20Frequencies%20Equal/README_EN.md) | | Hard | Weekly Contest 428 |
+| 3390 | [Longest Team Pass Streak](/solution/3300-3399/3390.Longest%20Team%20Pass%20Streak/README_EN.md) | | Hard | 🔒 |
## Copyright