Skip to content

Commit e868b83

Browse files
committed
Upload 128
1 parent d88512f commit e868b83

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ To make the daily tasks of creating a new file and updating the index easier, th
161161
| 125 | [Primary Department for Each Employee](https://leetcode.com/problems/primary-department-for-each-employee/description/) | [Solution](solutions/125_primary_department_for_each_employee.md) | LeetCode | Easy | `UNION` |
162162
| 126 | [Triangle Judgement](https://leetcode.com/problems/triangle-judgement/description/) | [Solution](solutions/126_triangle_judgement.md) | LeetCode | Easy | Triangle Inequality Theorem |
163163
| 127 | [Consecutive Numbers](https://leetcode.com/problems/consecutive-numbers/description/) | [Solution](solutions/127_consecutive_numbers.md) | LeetCode | Medium | |
164+
| 128 | [Last Person to Fit in the Bus](https://leetcode.com/problems/last-person-to-fit-in-the-bus/description/) | [Solution](solutions/128_last_person_to_fit_in_the_bus.md) | LeetCode | Medium | `ORDER BY turn RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW` |
164165

165166
## Author(s)
166167

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SQL Everyday \#128
2+
3+
## Last Person to Fit in the Bus
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
There is a queue of people waiting to board a bus. However, the bus has a weight limit of `1000` *kilograms*, so there may be some people who cannot board.
11+
12+
Write a solution to find the `person_name` of the *last person* that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight limit.
13+
14+
*Note* that _only one_ person can board the bus at any given turn. [[Full Description](https://leetcode.com/problems/last-person-to-fit-in-the-bus/description/)]
15+
16+
## Submitted Solution
17+
18+
```sql
19+
-- Submitted Solution
20+
WITH cte AS (
21+
SELECT
22+
*
23+
,SUM(weight) OVER (ORDER BY turn RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS total
24+
FROM Queue
25+
)
26+
SELECT
27+
person_name
28+
FROM cte
29+
WHERE total <= 1000
30+
ORDER BY total DESC
31+
LIMIT 1
32+
;
33+
```
34+
35+
## Site Solution
36+
37+
```sql
38+
-- LeetCode Solution
39+
-- None
40+
```
41+
42+
## Notes
43+
44+
TODO
45+
46+
Go to [Table of Contents](/README.md#contents)\
47+
Go to [Overview](/README.md)

0 commit comments

Comments
 (0)