Loading problem...
You are managing a shuttle service that operates along a single, one-way route with a fixed maximum passenger capacity. The shuttle travels in only one direction and cannot reverse course. Your goal is to determine whether the shuttle can successfully accommodate all passenger bookings without ever exceeding its seating capacity at any point during the journey.
You are given:
All stop locations are represented as non-negative integers indicating their position along the route. Passengers board at the pickup stop and exit at the dropoff stop. Crucially, passengers who exit at a given stop do so before new passengers board at the same stop.
Return true if all bookings can be fulfilled without exceeding the shuttle's capacity at any stop along the route, otherwise return false.
bookings = [[2,1,5],[3,3,7]]
maxCapacity = 4falseFrom stop 1 to stop 3, there are 2 passengers on the shuttle. At stop 3, 3 more passengers board, bringing the total to 5 passengers. Since the shuttle can only hold 4 passengers, the capacity is exceeded.
bookings = [[2,1,5],[3,3,7]]
maxCapacity = 5trueFrom stop 1 to stop 3, there are 2 passengers. At stop 3, 3 more passengers board, bringing the total to 5. At stop 5, the first 2 passengers exit, leaving 3 passengers until stop 7. The shuttle never exceeds its capacity of 5 at any point.
bookings = [[3,2,7]]
maxCapacity = 5trueOnly 3 passengers board at stop 2 and exit at stop 7. The capacity of 5 is never exceeded.
Constraints