Last Person to Fit in the Bus
Task: Find the name of the last person that can fit on the bus without exceeding the weight limit.
Table: Queue
+-------------+-------------+
| Column Name | Type |
+-------------+-------------+
| person_id | INT |
| person_name | varchar(30) |
| weight | INT |
| turn | INT |
+-------------+-------------+
Input: 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 |
+-----------+-------------+--------+------+
Output:
+-------------+
| person_name |
+-------------+
| John Cena |
+-------------+