Problem · Array
Minimum Seats for One-Way Car Pooling
Learn this problemProblem statement
A car travels in one direction along a route. You are given an array stops, where each row is [passengers, from, to].
passengerspeople enter the car at pointfrom.- The same people leave the car at point
to. - At a point where both events occur, passengers leaving the car get out before new passengers enter.
Return the minimum number of seats the car needs so that every trip can be completed. This is the maximum number of passengers simultaneously in the car.
Function
minimumSeats(stops: int[][]) → intExamples
Example 1
stops = [[2,1,5],[3,3,7]]return = 5Between points 3 and 5, both groups are in the car, so 2 + 3 = 5 seats are required.
Example 2
stops = [[2,1,5],[3,5,7]]return = 3At point 5, the first two passengers leave before the next three enter. The groups never overlap, so only 3 seats are needed.
Example 3
stops = [[4,0,10],[2,2,6],[5,6,8],[1,8,9]]return = 9At point 6, two passengers leave before five enter. The occupancy becomes 4 + 5 = 9, the maximum along the route.
Constraints
1 <= stops.length <= 10^5.- Every row in
stopshas exactly three integers. 1 <= passengers <= 10^4.0 <= from < to <= 10^9.- The sum of all
passengersvalues is at most10^9.