A ride-sharing app plans one shuttle that drives in one direction along a road. Each booking is [riders, from, to]: riders people get on at kilometer from and off at kilometer to. People getting off at a stop leave before new people get on there.
Write fitsInShuttle(bookings, seats) that returns true if the shuttle never carries more than seats people at once, and false otherwise.
Input: bookings = [[2,1,5],[3,3,7]], seats = 4 Output: false
Between kilometers 3 and 5 there are 2 + 3 = 5 riders.
Input: bookings = [[2,1,5],[3,5,7]], seats = 3 Output: true
The first group leaves at 5 before the second group gets on.
0 <= bookings.length <= 10001 <= riders <= 1000 <= from < to <= 10001 <= seats <= 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 #588 Shuttle Seats Never Exceeded. 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.