Passengers board a shuttle one at a time by boarding_order, and the shuttle's weight limit is 1200 kg. Return the passenger_name of the last passenger who can board without the cumulative weight exceeding the limit. The first passenger is guaranteed not to exceed the limit.
Input Table(s)
shuttle_queue has one row per passenger waiting to board.
| Column | Type | Meaning |
|---|
| passenger_id | int | Passenger identifier |
| passenger_name | varchar | Passenger's name |
| weight_kg | int | Passenger's weight in kilograms |
| boarding_order | int | Position in the boarding line: 1 boards first, n boards last |
Keys: passenger_id is the primary key. passenger_id and boarding_order each contain every number from 1 to n, where n is the number of rows, so boarding_order is unique too.
Output Contract
-
One column:
passenger_name
.
-
Exactly one row: the passenger with the highest
boarding_order
whose cumulative weight (their own weight plus the weight of everyone who boarded before them) is at most 1200 kg.
-
No rounding is involved.
Example
Input shuttle_queue:
| passenger_id | passenger_name | weight_kg | boarding_order |
|---|
| 1 | Maya | 400 | 3 |
| 2 | Omar | 350 | 1 |
| 3 | Lena | 500 | 4 |
| 4 | Theo | 300 | 2 |
| 5 | Rosa | 100 | 5 |
Expected output:
Omar boards first (350 kg on board), then Theo (650 kg), then Maya (1050 kg). Lena would bring the total to 1550 kg, so boarding stops after Maya. Rosa weighs only 100 kg, but she is behind Lena in line and cannot board ahead of her.
Constraints and Clarifications
-
The table has at least one row, and the first passenger to board always fits.
-
Boarding follows
boarding_order
strictly. Once the next passenger would push the total over 1200 kg, nobody after them boards, even a passenger light enough to fit on their own.
-
A cumulative weight of exactly 1200 kg is within the limit.
-
weight_kg
is a positive integer and is never NULL.
-
passenger_id
has no relation to the boarding order.