Skip to content

Commit 6364938

Browse files
author
Shuo
committed
A: new
1 parent 20ae929 commit 6364938

File tree

1 file changed

+47
-0
lines changed
  • problems/last-person-to-fit-in-the-elevator

1 file changed

+47
-0
lines changed

problems/last-person-to-fit-in-the-elevator/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,51 @@
1111

1212
## [1204. Last Person to Fit in the Elevator (Medium)](https://leetcode.com/problems/last-person-to-fit-in-the-elevator "最后一个能进入电梯的人")
1313

14+
<p>Table: <code>Queue</code></p>
1415

16+
<pre>
17+
+-------------+---------+
18+
| Column Name | Type |
19+
+-------------+---------+
20+
| person_id | int |
21+
| person_name | varchar |
22+
| weight | int |
23+
| turn | int |
24+
+-------------+---------+
25+
person_id is the primary key column for this table.
26+
This table has the information about all people waiting for an elevator.
27+
The <code>person_id</code>&nbsp;and <code>turn</code> columns will contain all numbers from 1 to n, where n is the number of rows in the table.
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
32+
<p>The maximum weight the elevator can hold is <strong>1000</strong>.</p>
33+
34+
<p>Write an SQL query to find the&nbsp;<code>person_name</code> of the last person who will fit in the elevator without exceeding the weight limit. It is guaranteed that the person who is&nbsp;first in the queue can fit in the elevator.</p>
35+
36+
<p>The query result format is in the following example:</p>
37+
38+
<pre>
39+
Queue table
40+
+-----------+-------------------+--------+------+
41+
| person_id | person_name | weight | turn |
42+
+-----------+-------------------+--------+------+
43+
| 5 | George Washington | 250 | 1 |
44+
| 3 | John Adams | 350 | 2 |
45+
| 6 | Thomas Jefferson | 400 | 3 |
46+
| 2 | Will Johnliams | 200 | 4 |
47+
| 4 | Thomas Jefferson | 175 | 5 |
48+
| 1 | James Elephant | 500 | 6 |
49+
+-----------+-------------------+--------+------+
50+
51+
Result table
52+
+-------------------+
53+
| person_name |
54+
+-------------------+
55+
| Thomas Jefferson |
56+
+-------------------+
57+
58+
Queue table is ordered by turn in the example for simplicity.
59+
In the example George Washington(id 5), John Adams(id 3) and Thomas Jefferson(id 6) will enter the elevator as their weight sum is 250 + 350 + 400 = 1000.
60+
Thomas Jefferson(id 6) is the last person to fit in the elevator because he has the last turn in these three people.
61+
</pre>

0 commit comments

Comments
 (0)