Last Passenger to Board the Shuttle

Quick Overview

A SQL problem about a shuttle with a 1200 kg weight limit: passengers board in a fixed order, and you return the name of the last one who fits. It tests running totals over an ordered column, inclusive limit checks, and picking a single row with the correct ordering key.

Last Passenger to Board the Shuttle

Company: Wayfair

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

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. ```hint Track the load Look at the total weight on board after each passenger, taken in boarding order. ``` ### 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: | passenger_name | |---| | Maya | 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.

Overview: A SQL problem about a shuttle with a 1200 kg weight limit: passengers board in a fixed order, and you return the name of the last one who fits. It tests running totals over an ordered column, inclusive limit checks, and picking a single row with the correct ordering key.

Wayfair logo
Wayfair
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

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.

ColumnTypeMeaning
passenger_idintPassenger identifier
passenger_namevarcharPassenger's name
weight_kgintPassenger's weight in kilograms
boarding_orderintPosition 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_idpassenger_nameweight_kgboarding_order
1Maya4003
2Omar3501
3Lena5004
4Theo3002
5Rosa1005

Expected output:

passenger_name
Maya

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.