Vehicle Maintenance Event Readiness
Problem statement
Each row in events is [action, time, maintenanceType]. Rows are ordered by nondecreasing integer time, and rows are processed in the given order. An OPEN row starts maintenance of that type, and an END row finishes the active maintenance of that type.
Each maintenance type can have at most one active event at a time. After a type ends, it may be opened again later.
A row is invalid when it opens a type that is already active or ends a type that is not active. The vehicle is ready exactly when no row is invalid and no maintenance event is still active after the last row.
Return whether the vehicle is ready.
Function
isVehicleReady(events: String[][]) → booleanExamples
Example 1
events = [["OPEN","10","oil"],["OPEN","12","brake"],["END","20","oil"],["END","25","brake"]]return = trueOil and brake maintenance overlap, but they are different types. Each one ends, so the vehicle is ready.
Example 2
events = [["OPEN","1","oil"],["END","4","oil"],["OPEN","8","oil"],["END","9","oil"]]return = trueOil maintenance happens twice. The second OPEN comes after the first END, so the two oil events never overlap. Both end, so the vehicle is ready.
Example 3
events = [["END","3","brake"]]return = falseBrake maintenance is not active, so it cannot end.
Example 4
events = [["OPEN","1","brake"],["OPEN","2","brake"],["END","3","brake"],["END","4","brake"]]return = falseThe second brake OPEN happens while brake maintenance is still active, so two brake events would overlap.
Constraints
0 <= events.length <= 100000.- Each row contains exactly three strings in the format above.
- Each action is
OPENorEND. - Times are decimal integers in
[0, 10^9]and are nondecreasing. - Maintenance types contain 1 to 40 visible ASCII characters.