Practice Last Person to Fit in the Bus
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: Queue(person_id INT, person_name VARCHAR, weight INT, turn INT). Queue.person_id is unique; person_id and turn each contain 1 through n. turn sets boarding order and weight is in kilograms. The first person fits. Return person_name for the last person in the boarding prefix whose cumulative weight does not exceed 1000 kilograms. Board in increasing turn order; do not skip an earlier person to admit a later lighter person.
Source: Last Person to Fit in the Bus on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Queue table: +-----------+-------------+--------+------+ | person_id | person_name | weight | turn | +-----------+-------------+--------+------+ | 5 | Alice | 250 | 1 | | 4 | Bob | 175 | 5 | | 3 | Alex | 350 | 2 | | 6 | John Cena | 400 | 3 | | 1 | Winston | 500 | 6 | | 2 | Marie | 200 | 4 | +-----------+-------------+--------+------+
+-------------+ | person_name | +-------------+ | John Cena | +-------------+
Related LeetCode Problems
Practice more problems similar to Last Person to Fit in the Bus.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.