A conference shuttle drives one way past stops numbered 0 to 1000 and holds at most capacity people. Each ride request [people, from, to] boards people at stop from and drops them at stop to.
At any stop, people getting off leave before new people get on. Write canCarryEveryone(trips, capacity) that returns true if every request fits without ever going over capacity.
Input: trips = [[3,0,4],[2,2,6],[4,4,7]], capacity = 5 Output: false
At stop 4, three people leave and four board, so 6 people ride with 5 seats.
Input: trips = [[3,0,4],[2,2,6],[4,4,7]], capacity = 6 Output: true
The busiest moment has 6 riders, which fits.
0 <= trips.length <= 10001 <= people <= 1000 <= from < to <= 10001 <= capacity <= 10^5Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #56 Can the Shuttle Carry Everyone. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.