Last Person on the Bus
queue has columns name, weight and turn (all turns are different). People board in order of turn, smallest first, and boarding stops as soon as the next person would push the total weight above limit. Return the name of the last person who boards. The first person always fits.
Example 1
queue {"name":["a","b","c"],"weight":[300,400,500],"turn":[2,1,3]}
limit 1000
returns "a"
b (400), a (700), then c would reach 1200.
Constraints
- Weights are positive
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More pandas problems
- Manager NamesMedium
- Most Orders CustomerMedium
- Most Recent OrderMedium
- Person CitiesMedium
- Rearrange Products TableMedium
- Record ReadingsMedium
- Reformat Department TableMedium
- Revenue per ProductMedium