AnalystPath

Last Person to Board the Bus

SQLMediumMid level~15 min

Problem

**[Classic — asked at multiple companies including Uber, DoorDash]**

People queue to board a bus with a **1 000 kg weight limit**. They board in
`turn` order (turn=1 first). Each person boards only if the cumulative weight
does NOT exceed 1 000 kg.

Find the `person_name` of the **last person who can board** without the
total exceeding 1 000 kg.

Tables

Example rows — the live problem includes the full dataset.

queue
person_idperson_nameweightturn

Expected output

Your answer should return 1 row with the columns person_name.

Starter code (SQL)

SELECT *
FROM queue;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions