FastPrepVehicle Maintenance Event Readiness

Vehicle Maintenance Event Readiness

Waymo logoWaymo● EasyFULLTIMEPHONE SCREEN
Learn

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[][]) → boolean

Examples

Example 1

events = [["OPEN","10","oil"],["OPEN","12","brake"],["END","20","oil"],["END","25","brake"]]return = true

Both distinct maintenance lifecycles end successfully.

Example 2

events = [["OPEN","1","oil"],["END","4","oil"],["OPEN","8","oil"]]return = false

The same type starts a second lifecycle, which is not permitted.

Example 3

events = [["END","3","brake"]]return = false

An inactive maintenance type cannot end.

Constraints

  • 0 <= events.length <= 100000.
  • Each row contains exactly three strings in the format above.
  • Each action is OPEN or END.
  • Times are decimal integers in [0, 10^9] and are nondecreasing.
  • Maintenance types contain 1 to 40 visible ASCII characters.

More Waymo problems

See Waymo hiring insights
public boolean isVehicleReady(String[][] events) {
    // Write your solution here.
}
events[["OPEN","10","oil"],["OPEN","12","brake"],["END","20","oil"],["END","25","brake"]]
expectedtrue
Checking account…