Skip to content

chore: add new lc problems #1326

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 1 commit into from
Jul 28, 2023
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
102 changes: 102 additions & 0 deletions solution/2700-2799/2793.Status of Flight Tickets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# [2793. 航班机票状态](https://leetcode.cn/problems/status-of-flight-tickets)

[English Version](/solution/2700-2799/2793.Status%20of%20Flight%20Tickets/README_EN.md)

## 题目描述

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

<p>表:&nbsp;<code><font face="monospace">Flights</font></code></p>

<pre>
+-------------+------+
| 列名 | 类型 |
+-------------+------+
| flight_id | int |
| capacity | int |
+-------------+------+
flight_id 是该表的主键列。
每行包含航班 id 和座位容量。
</pre>

<p>表:<code>Passengers</code></p>

<pre>
+--------------+----------+
| 列名 | 类型 |
+--------------+----------+
| passenger_id | int |
| flight_id | int |
| booking_time | datetime |
+--------------+----------+
passenger_id 是该表的主键。
booking_time 包含不同的值。
每行包含乘客 id、预订时间和所预订的航班 id。
</pre>

<p>乘客提前预订航班机票。如果乘客预订了一张航班机票,并且航班上还有空座位,则乘客的机票将 <strong>得到确认</strong> 。然而,如果航班已经满员,乘客将被列入 <strong>等候名单</strong> 。</p>

<p>编写一个 SQL 查询来确定每个乘客航班机票的当前状态。</p>

<p>按 <code>passenger_id</code> <strong>升序排序&nbsp;</strong>返回结果表。</p>

<p>查询结果的格式如下所示。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<pre>
<b>输入:</b>
Flights 表:
+-----------+----------+
| flight_id | capacity |
+-----------+----------+
| 1 | 2 |
| 2 | 2 |
| 3 | 1 |
+-----------+----------+
Passengers 表:
+--------------+-----------+---------------------+
| passenger_id | flight_id | booking_time |
+--------------+-----------+---------------------+
| 101 | 1 | 2023-07-10 16:30:00 |
| 102 | 1 | 2023-07-10 17:45:00 |
| 103 | 1 | 2023-07-10 12:00:00 |
| 104 | 2 | 2023-07-05 13:23:00 |
| 105 | 2 | 2023-07-05 09:00:00 |
| 106 | 3 | 2023-07-08 11:10:00 |
| 107 | 3 | 2023-07-08 09:10:00 |
+--------------+-----------+---------------------+
<b>输出:</b>
+--------------+-----------+
| passenger_id | Status |
+--------------+-----------+
| 101 | Confirmed |
| 102 | Waitlist |
| 103 | Confirmed |
| 104 | Confirmed |
| 105 | Confirmed |
| 106 | Waitlist |
| 107 | Confirmed |
+--------------+-----------+
<b>解释:</b>
- 航班 1 的容量为 2 位乘客。乘客 101 和乘客 103 是最先预订机票的,已经确认他们的预订。然而,乘客 102 是第三位预订该航班的乘客,这意味着没有更多的可用座位。乘客 102 现在被列入等候名单。
- 航班 2 的容量为 2 位乘客,已经有两位乘客预订了机票,乘客 104 和乘客 105。由于预订机票的乘客数与可用座位数相符,这两个预订都得到了确认。
- 航班 3 的容量为 1 位乘客,乘客 107 先预订并获得了唯一的可用座位,确认了他们的预订。预订时间在乘客 107 之后的乘客 106 被列入等候名单。</pre>

## 解法

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

<!-- tabs:start -->

### **SQL**

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

```sql

```

<!-- tabs:end -->
96 changes: 96 additions & 0 deletions solution/2700-2799/2793.Status of Flight Tickets/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# [2793. Status of Flight Tickets](https://leetcode.com/problems/status-of-flight-tickets)

[中文文档](/solution/2700-2799/2793.Status%20of%20Flight%20Tickets/README.md)

## Description

<p>Table: <code><font face="monospace">Flights</font></code></p>

<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| flight_id | int |
| capacity | int |
+-------------+------+
<code>flight_id</code> is the primary key column for this table.
Each row of this table contains flight id and capacity.
</pre>

<p>Table: <code>Passengers</code></p>

<pre>
+--------------+----------+
| Column Name | Type |
+--------------+----------+
| passenger_id | int |
| flight_id | int |
| booking_time | datetime |
+--------------+----------+
passenger_id is the primary key column for this table.
booking_time column contains distinct values.
Each row of this table contains passenger id, booking time, and their flight id.
</pre>

<p>Passengers book tickets for flights in advance. If a passenger books a ticket for a flight and there are still empty seats available on the flight, the passenger&#39;s ticket will be <strong>confirmed</strong>. However, the passenger will be on a <strong>waitlist</strong> if the flight is already at full capacity.</p>

<p>Write an SQL query to determine the current status of flight tickets for each passenger.</p>

<p>Return <em>the result table ordered by</em> <code>passenger_id</code> <em>in <strong>ascending order</strong>.</em></p>

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

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

<pre>
<strong>Input:</strong>
Flights table:
+-----------+----------+
| flight_id | capacity |
+-----------+----------+
| 1 | 2 |
| 2 | 2 |
| 3 | 1 |
+-----------+----------+
Passengers table:
+--------------+-----------+---------------------+
| passenger_id | flight_id | booking_time |
+--------------+-----------+---------------------+
| 101 | 1 | 2023-07-10 16:30:00 |
| 102 | 1 | 2023-07-10 17:45:00 |
| 103 | 1 | 2023-07-10 12:00:00 |
| 104 | 2 | 2023-07-05 13:23:00 |
| 105 | 2 | 2023-07-05 09:00:00 |
| 106 | 3 | 2023-07-08 11:10:00 |
| 107 | 3 | 2023-07-08 09:10:00 |
+--------------+-----------+---------------------+
<strong>Output:</strong>
+--------------+-----------+
| passenger_id | Status |
+--------------+-----------+
| 101 | Confirmed |
| 102 | Waitlist |
| 103 | Confirmed |
| 104 | Confirmed |
| 105 | Confirmed |
| 106 | Waitlist |
| 107 | Confirmed |
+--------------+-----------+
<strong>Explanation:</strong>
- Flight 1 has a capacity of 2 passengers. Passenger 101 and Passenger 103 were the first to book tickets, securing the available seats. Therefore, their bookings are confirmed. However, Passenger 102 was the third person to book a ticket for this flight, which means there are no more available seats. Passenger 102 is now placed on the waitlist,
- Flight 2 has a capacity of 2 passengers, Flight 2 has exactly two passengers who booked tickets, Passenger 104 and Passenger 105. Since the number of passengers who booked tickets matches the available seats, both bookings are confirmed.
- Flight 3 has a capacity of 1 passenger. Passenger 107 booked earlier and secured the only available seat, confirming their booking. Passenger 106, who booked after Passenger 107, is on the waitlist.
</pre>

## Solutions

<!-- tabs:start -->

### **SQL**

```sql

```

<!-- tabs:end -->
66 changes: 66 additions & 0 deletions solution/2700-2799/2794.Create Object from Two Arrays/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# [2794. 从两个数组中创建对象](https://leetcode.cn/problems/create-object-from-two-arrays)

[English Version](/solution/2700-2799/2794.Create%20Object%20from%20Two%20Arrays/README_EN.md)

## 题目描述

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

<p>给定两个数组 <code>keysArr </code>和 <code>valuesArr</code>,返回一个新的对象 <code>obj</code>。<code>obj</code> 中的每个键值对都来自 <code>keysArr[i]</code> 和 <code>valuesArr[i]</code>。</p>

<p>- 如果前面的索引中存在重复的键,则应该跳过该键值对。换句话说,只有第一次出现的键会被添加到对象中。</p>

<p>- 如果键不是字符串,则应通过调用 <code>String()</code> 方法将其转换为字符串。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<pre>
<b>输入:</b>arr1 = ["a", "b", "c"], arr2 = [1, 2, 3]
<b>输出:</b>{"a": 1, "b": 2, "c": 3}
<b>解释:</b>键 "a"、"b" 和 "c" 分别与值 1、2 和 3 配对。
</pre>

<p><strong class="example">示例 2:</strong></p>

<pre>
<b>输入:</b>arr1 = ["1", 1, false], arr2 = [4, 5, 6]
<b>输出:</b>{"1": 4, "false": 6}
<b>解释:</b>首先,将 arr1 中的所有元素转换为字符串。我们可以看到有两个 "1" 的出现。使用第一次出现 "1" 的关联值:4。
</pre>

<p><strong class="example">示例 3:</strong></p>

<pre>
<b>输入:</b>arr1 = [], arr2 = []
<b>输出:</b>{}
<b>解释:</b>没有键,因此返回一个空对象。
</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>arr1 和 arr2 都是有效的 JSON 数组</code></li>
<li><code>2 &lt;= JSON.stringify(arr1).length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>2 &lt;= JSON.stringify(arr2).length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>arr1.length === arr2.length</code></li>
</ul>

## 解法

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

<!-- tabs:start -->

### **TypeScript**

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

```ts

```

<!-- tabs:end -->
58 changes: 58 additions & 0 deletions solution/2700-2799/2794.Create Object from Two Arrays/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# [2794. Create Object from Two Arrays](https://leetcode.com/problems/create-object-from-two-arrays)

[中文文档](/solution/2700-2799/2794.Create%20Object%20from%20Two%20Arrays/README.md)

## Description

<p>Given two arrays <code>keysArr</code> and <code>valuesArr</code>, return a new object <code>obj</code>. Each key-value pair in&nbsp;<code>obj</code>&nbsp;should come from&nbsp;<code>keysArr[i]</code>&nbsp;and&nbsp;<code>valuesArr[i]</code>.</p>

<p>- If a duplicate key exists at a previous index, that key-value should be excluded. In other words, only the first key should be added to the object.</p>

<p>- If the key is not a string, it should be converted into a string by calling `String()` on it.</p>

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

<pre>
<strong>Input:</strong> arr1 = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;], arr2 = [1, 2, 3]
<strong>Output:</strong> {&quot;a&quot;: 1, &quot;b&quot;: 2, &quot;c&quot;: 3}
<strong>Explanation:</strong> The keys &quot;a&quot;, &quot;b&quot;, and &quot;c&quot; are paired with the values 1, 2, and 3 respectively.
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [&quot;1&quot;, 1, false], arr2 = [4, 5, 6]
<strong>Output:</strong> {&quot;1&quot;: 4, &quot;false&quot;: 6}
<strong>Explanation:</strong> First, all the elements in arr1 are converted into strings. We can see there are two occurrences of &quot;1&quot;. The value associated with the first occurrence of &quot;1&quot; is used: 4.
</pre>

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

<pre>
<strong>Input:</strong> arr1 = [], arr2 = []
<strong>Output:</strong> {}
<strong>Explanation:</strong> There are no keys so an empty object is returned.
</pre>

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

<ul>
<li><code>arr1 and arr2 are valid JSON arrays</code></li>
<li><code>2 &lt;= JSON.stringify(arr1).length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>2 &lt;= JSON.stringify(arr2).length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>arr1.length === arr2.length</code></li>
</ul>

## Solutions

<!-- tabs:start -->

### **TypeScript**

```ts

```

<!-- tabs:end -->
Loading