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 new lc problems #2181

Merged
merged 2 commits into from
Jan 5, 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
76 changes: 76 additions & 0 deletions solution/2900-2999/2993.Friday Purchases I/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# [2993. Friday Purchases I](https://leetcode.cn/problems/friday-purchases-i)

[English Version](/solution/2900-2999/2993.Friday%20Purchases%20I/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>Table: <code>Purchases</code></p>

<pre>
+---------------+------+
| Column Name | Type |
+---------------+------+
| user_id | int |
| purchase_date | date |
| amount_spend | int |
+---------------+------+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
Each row contains user id, purchase date, and amount spend.
</pre>

<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. Output only weeks that include <strong>at least one</strong> purchase on a <strong>Friday</strong>.</p>

<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>

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

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

<pre>
<strong>Input:</strong>
Purchases table:
+---------+---------------+--------------+
| user_id | purchase_date | amount_spend |
+---------+---------------+--------------+
| 11 | 2023-11-07 | 1126 |
| 15 | 2023-11-30 | 7473 |
| 17 | 2023-11-14 | 2414 |
| 12 | 2023-11-24 | 9692 |
| 8 | 2023-11-03 | 5117 |
| 1 | 2023-11-16 | 5241 |
| 10 | 2023-11-12 | 8266 |
| 13 | 2023-11-24 | 12000 |
+---------+---------------+--------------+
<strong>Output:</strong>
+---------------+---------------+--------------+
| week_of_month | purchase_date | total_amount |
+---------------+---------------+--------------+
| 1 | 2023-11-03 | 5117 |
| 4 | 2023-11-24 | 21692 |
+---------------+---------------+--------------+
<strong>Explanation:</strong>
- During the first week of November 2023, transactions amounting to $5,117 occurred on Friday, 2023-11-03.
- For the second week of November 2023, there were no transactions on Friday, 2023-11-10.
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023-11-17.
- In the fourth week of November 2023, two transactions took place on Friday, 2023-11-24, amounting to $12,000 and $9,692 respectively, summing up to a total of $21,692.
Output table is ordered by week_of_month in ascending order.</pre>

## 解法

<!-- 这里可写通用的实现逻辑 -->

<!-- tabs:start -->

### **SQL**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```sql

```

<!-- tabs:end -->
70 changes: 70 additions & 0 deletions solution/2900-2999/2993.Friday Purchases I/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# [2993. Friday Purchases I](https://leetcode.com/problems/friday-purchases-i)

[中文文档](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md)

## Description

<p>Table: <code>Purchases</code></p>

<pre>
+---------------+------+
| Column Name | Type |
+---------------+------+
| user_id | int |
| purchase_date | date |
| amount_spend | int |
+---------------+------+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
Each row contains user id, purchase date, and amount spend.
</pre>

<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. Output only weeks that include <strong>at least one</strong> purchase on a <strong>Friday</strong>.</p>

<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>

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

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

<pre>
<strong>Input:</strong>
Purchases table:
+---------+---------------+--------------+
| user_id | purchase_date | amount_spend |
+---------+---------------+--------------+
| 11 | 2023-11-07 | 1126 |
| 15 | 2023-11-30 | 7473 |
| 17 | 2023-11-14 | 2414 |
| 12 | 2023-11-24 | 9692 |
| 8 | 2023-11-03 | 5117 |
| 1 | 2023-11-16 | 5241 |
| 10 | 2023-11-12 | 8266 |
| 13 | 2023-11-24 | 12000 |
+---------+---------------+--------------+
<strong>Output:</strong>
+---------------+---------------+--------------+
| week_of_month | purchase_date | total_amount |
+---------------+---------------+--------------+
| 1 | 2023-11-03 | 5117 |
| 4 | 2023-11-24 | 21692 |
+---------------+---------------+--------------+
<strong>Explanation:</strong>
- During the first week of November 2023, transactions amounting to $5,117 occurred on Friday, 2023-11-03.
- For the second week of November 2023, there were no transactions on Friday, 2023-11-10.
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023-11-17.
- In the fourth week of November 2023, two transactions took place on Friday, 2023-11-24, amounting to $12,000 and $9,692 respectively, summing up to a total of $21,692.
Output table is ordered by week_of_month in ascending order.</pre>

## Solutions

<!-- tabs:start -->

### **SQL**

```sql

```

<!-- tabs:end -->
78 changes: 78 additions & 0 deletions solution/2900-2999/2994.Friday Purchases II/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# [2994. Friday Purchases II](https://leetcode.cn/problems/friday-purchases-ii)

[English Version](/solution/2900-2999/2994.Friday%20Purchases%20II/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>Table: <code>Purchases</code></p>

<pre>
+---------------+------+
| Column Name | Type |
+---------------+------+
| user_id | int |
| purchase_date | date |
| amount_spend | int |
+---------------+------+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
Each row contains user id, purchase date, and amount spend.
</pre>

<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. If there are <strong>no</strong> purchases on a particular <strong>Friday of a week</strong>, it will be considered as <code>0</code>.</p>

<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>

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

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

<pre>
<strong>Input:</strong>
Purchases table:
+---------+---------------+--------------+
| user_id | purchase_date | amount_spend |
+---------+---------------+--------------+
| 11 | 2023-11-07 | 1126 |
| 15 | 2023-11-30 | 7473 |
| 17 | 2023-11-14 | 2414 |
| 12 | 2023-11-24 | 9692 |
| 8 | 2023-11-03 | 5117 |
| 1 | 2023-11-16 | 5241 |
| 10 | 2023-11-12 | 8266 |
| 13 | 2023-11-24 | 12000 |
+---------+---------------+--------------+
<strong>Output:</strong>
+---------------+---------------+--------------+
| week_of_month | purchase_date | total_amount |
+---------------+---------------+--------------+
| 1 | 2023-11-03 | 5117 |
| 2 | 2023-11-10 | 0 |
| 3 | 2023-11-17 | 0 |
| 4 | 2023-11-24 | 21692 |
+---------------+---------------+--------------+
<strong>Explanation:</strong>
- During the first week of November 2023, transactions amounting to $5,117 occurred on Friday, 2023-11-03.
- For the second week of November 2023, there were no transactions on Friday, 2023-11-10, resulting in a value of 0 in the output table for that day.
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023-11-17, reflected as 0 in the output table for that specific day.
- In the fourth week of November 2023, two transactions took place on Friday, 2023-11-24, amounting to $12,000 and $9,692 respectively, summing up to a total of $21,692.
Output table is ordered by week_of_month in ascending order.</pre>

## 解法

<!-- 这里可写通用的实现逻辑 -->

<!-- tabs:start -->

### **SQL**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```sql

```

<!-- tabs:end -->
72 changes: 72 additions & 0 deletions solution/2900-2999/2994.Friday Purchases II/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# [2994. Friday Purchases II](https://leetcode.com/problems/friday-purchases-ii)

[中文文档](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md)

## Description

<p>Table: <code>Purchases</code></p>

<pre>
+---------------+------+
| Column Name | Type |
+---------------+------+
| user_id | int |
| purchase_date | date |
| amount_spend | int |
+---------------+------+
(user_id, purchase_date, amount_spend) is the primary key (combination of columns with unique values) for this table.
purchase_date will range from November 1, 2023, to November 30, 2023, inclusive of both dates.
Each row contains user id, purchase date, and amount spend.
</pre>

<p>Write a solution to calculate the <strong>total spending</strong> by users on <strong>each Friday</strong> of <strong>every week</strong> in <strong>November 2023</strong>. If there are <strong>no</strong> purchases on a particular <strong>Friday of a week</strong>, it will be considered as <code>0</code>.</p>

<p>Return <em>the result table ordered by week of month</em><em> in <strong>ascending</strong></em><em><strong> </strong>order.</em></p>

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

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

<pre>
<strong>Input:</strong>
Purchases table:
+---------+---------------+--------------+
| user_id | purchase_date | amount_spend |
+---------+---------------+--------------+
| 11 | 2023-11-07 | 1126 |
| 15 | 2023-11-30 | 7473 |
| 17 | 2023-11-14 | 2414 |
| 12 | 2023-11-24 | 9692 |
| 8 | 2023-11-03 | 5117 |
| 1 | 2023-11-16 | 5241 |
| 10 | 2023-11-12 | 8266 |
| 13 | 2023-11-24 | 12000 |
+---------+---------------+--------------+
<strong>Output:</strong>
+---------------+---------------+--------------+
| week_of_month | purchase_date | total_amount |
+---------------+---------------+--------------+
| 1 | 2023-11-03 | 5117 |
| 2 | 2023-11-10 | 0 |
| 3 | 2023-11-17 | 0 |
| 4 | 2023-11-24 | 21692 |
+---------------+---------------+--------------+
<strong>Explanation:</strong>
- During the first week of November 2023, transactions amounting to $5,117 occurred on Friday, 2023-11-03.
- For the second week of November 2023, there were no transactions on Friday, 2023-11-10, resulting in a value of 0 in the output table for that day.
- Similarly, during the third week of November 2023, there were no transactions on Friday, 2023-11-17, reflected as 0 in the output table for that specific day.
- In the fourth week of November 2023, two transactions took place on Friday, 2023-11-24, amounting to $12,000 and $9,692 respectively, summing up to a total of $21,692.
Output table is ordered by week_of_month in ascending order.</pre>

## Solutions

<!-- tabs:start -->

### **SQL**

```sql

```

<!-- tabs:end -->
78 changes: 78 additions & 0 deletions solution/2900-2999/2995.Viewers Turned Streamers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# [2995. 观众变主播](https://leetcode.cn/problems/viewers-turned-streamers)

[English Version](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>表:&nbsp;<code>Sessions</code></p>

<pre>
+---------------+----------+
| Column Name | Type |
+---------------+----------+
| user_id | int |
| session_start | datetime |
| session_end | datetime |
| session_id | int |
| session_type | enum |
+---------------+----------+
session_id 是这张表具有唯一值的列。
session_type 是一个 ENUM (枚举) 类型,包含(Viewer, Streamer)两个类别。
这张表包含 user id, session start, session end, session id 和 session type。
</pre>

<p>编写一个解决方案,找到&nbsp;<strong>首次会话&nbsp;</strong>为 <strong>观众</strong> 的用户的&nbsp;<strong>会话&nbsp;</strong>数量。</p>

<p>按照会话数量和 <code>user_id</code> <strong>降序</strong> 排序返回结果表。</p>

<p>结果格式如下例所示。</p>

<p>&nbsp;</p>

<p><b>示例 1:</b></p>

<pre>
<b>输入:</b>
Sessions table:
+---------+---------------------+---------------------+------------+--------------+
| user_id | session_start | session_end | session_id | session_type |
+---------+---------------------+---------------------+------------+--------------+
| 101 | 2023-11-06 13:53:42 | 2023-11-06 14:05:42 | 375 | Viewer |
| 101 | 2023-11-22 16:45:21 | 2023-11-22 20:39:21 | 594 | Streamer |
| 102 | 2023-11-16 13:23:09 | 2023-11-16 16:10:09 | 777 | Streamer |
| 102 | 2023-11-17 13:23:09 | 2023-11-17 16:10:09 | 778 | Streamer |
| 101 | 2023-11-20 07:16:06 | 2023-11-20 08:33:06 | 315 | Streamer |
| 104 | 2023-11-27 03:10:49 | 2023-11-27 03:30:49 | 797 | Viewer |
| 103 | 2023-11-27 03:10:49 | 2023-11-27 03:30:49 | 798 | Streamer |
+---------+---------------------+---------------------+------------+--------------+
<b>输出:</b>
+---------+----------------+
| user_id | sessions_count |
+---------+----------------+
| 101 | 2 |
+---------+----------------+
<b>解释</b>
- user_id 101,在 2023-11-06 13:53:42 以观众身份开始了他们的初始会话,随后进行了两次主播会话,所以计数为 2。
- user_id 102,尽管有两个会话,但初始会话是作为主播,因此将排除此用户。
- user_id 103 只参与了一次会话,即作为主播,因此不会考虑在内。
- User_id 104 以观众身份开始了他们的第一次会话,但没有后续会话,因此不会包括在最终计数中。
输出表按照会话数量和 user_id 降序排序。
</pre>

## 解法

<!-- 这里可写通用的实现逻辑 -->

<!-- tabs:start -->

### **SQL**

<!-- 这里可写当前语言的特殊实现逻辑 -->

```sql

```

<!-- tabs:end -->
Loading