Vehicle Maintenance Event Readiness
Problem statement
Each row in events is [action, time, maintenanceType]. Rows are ordered by nondecreasing integer time. An OPEN row starts maintenance of that type, and an END row finishes it.
The vehicle is ready exactly when every lifecycle is valid and every opened maintenance event has ended. A lifecycle is invalid when a type is opened while already active, ends while inactive, or is opened again after its completed lifecycle.
Return whether the vehicle is ready after all rows are processed.
Function
isVehicleReady(events: String[][]) → booleanExamples
Example 1
events = [["OPEN","10","oil"],["OPEN","12","brake"],["END","20","oil"],["END","25","brake"]]return = trueBoth distinct maintenance lifecycles end successfully.
Example 2
events = [["OPEN","1","oil"],["END","4","oil"],["OPEN","8","oil"]]return = falseThe same type starts a second lifecycle, which is not permitted.
Example 3
events = [["END","3","brake"]]return = falseAn inactive maintenance type cannot end.
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.