Decide If a Vehicle Is Ready to Go from Open/End Maintenance Events

Quick Overview

Given a vehicle maintenance log of open and end events with timestamps and maintenance types such as oil or brake, decide whether the vehicle is ready to go. The problem tests chronological event processing with a stable tie rule, per-type state tracking, and detecting unmatched ends, overlapping opens, and tasks left open.

Decide If a Vehicle Is Ready to Go from Open/End Maintenance Events

Company: Waymo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

A vehicle may be released for its next trip only when all of its maintenance work has been closed out. Its maintenance log is a list of events, given as three parallel arrays. For event `i`: - `actions[i]` is either `"open"` (a maintenance task of that type starts) or `"end"` (the open task of that type is closed); - `times[i]` is the time at which the event happened; - `types[i]` names the kind of maintenance, such as `"oil"` or `"brake"`. Return `True` if the vehicle is ready to go and `False` otherwise. The vehicle is ready to go exactly when every event in the log is valid under the rules below and no maintenance task is still open after the last event has been processed. ### Function Signature ```python def is_ready_to_go(actions: list[str], times: list[int], types: list[str]) -> bool: ``` ### Rules - The events are not necessarily listed in chronological order. Process them in ascending order of `times[i]`; events with equal times are processed in the order they appear in the input (smaller index first). - Each maintenance type can have at most one open task at a time. An `"open"` event for type `t` is invalid if a task of type `t` is already open at that point. - Every `"end"` must close an open task of the same type. An `"end"` event for type `t` is invalid if no task of type `t` is open at that point. - Once a task of type `t` has been closed, a later `"open"` event for type `t` is valid again. - Types are compared exactly. Tasks of different types never affect each other, so any number of different types may be open at the same time. - If any event is invalid, the answer is `False`. An empty log has no outstanding maintenance, so its answer is `True`. ### Constraints - `0 <= len(actions) == len(times) == len(types) <= 100000` - `actions[i]` is exactly `"open"` or `"end"`. - `0 <= times[i] <= 10^9` - `types[i]` is a non-empty string of 1 to 20 lowercase English letters. - The answer is a single boolean and is uniquely determined by the input. ### Examples **Example 1** - Input: `actions = ["open", "open", "end", "end"]`, `times = [1, 2, 3, 4]`, `types = ["oil", "brake", "brake", "oil"]` - Output: `True` - Explanation: The oil task is open from time 1 to time 4 and the brake task from time 2 to time 3. Different types may be open together, both tasks are closed, and nothing remains open. **Example 2** - Input: `actions = ["open", "open", "end", "end"]`, `times = [1, 2, 3, 4]`, `types = ["oil", "oil", "oil", "oil"]` - Output: `False` - Explanation: At time 2 an oil task is opened while the oil task opened at time 1 is still open, which is invalid even though the log contains as many `"end"` events as `"open"` events. **Example 3** - Input: `actions = ["end", "open", "end", "open"]`, `times = [9, 1, 3, 6]`, `types = ["tire", "tire", "tire", "tire"]` - Output: `True` - Explanation: In time order the events are: open at 1, end at 3, open at 6, end at 9. The second tire task starts only after the first one has been closed, and both are closed by the end of the log.

Overview: Given a vehicle maintenance log of open and end events with timestamps and maintenance types such as oil or brake, decide whether the vehicle is ready to go. The problem tests chronological event processing with a stable tie rule, per-type state tracking, and detecting unmatched ends, overlapping opens, and tasks left open.

|Home/Coding & Algorithms/Waymo
Waymo logo
Waymo
Sep 5, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
0
0

A vehicle may be released for its next trip only when all of its maintenance work has been closed out. Its maintenance log is a list of events, given as three parallel arrays. For event i:

  • actions[i] is either "open" (a maintenance task of that type starts) or "end" (the open task of that type is closed);
  • times[i] is the time at which the event happened;
  • types[i] names the kind of maintenance, such as "oil" or "brake" .

Return True if the vehicle is ready to go and False otherwise. The vehicle is ready to go exactly when every event in the log is valid under the rules below and no maintenance task is still open after the last event has been processed.

Function Signature

def is_ready_to_go(actions: list[str], times: list[int], types: list[str]) -> bool:

Rules

  • The events are not necessarily listed in chronological order. Process them in ascending order of times[i] ; events with equal times are processed in the order they appear in the input (smaller index first).
  • Each maintenance type can have at most one open task at a time. An "open" event for type t is invalid if a task of type t is already open at that point.
  • Every "end" must close an open task of the same type. An "end" event for type t is invalid if no task of type t is open at that point.
  • Once a task of type t has been closed, a later "open" event for type t is valid again.
  • Types are compared exactly. Tasks of different types never affect each other, so any number of different types may be open at the same time.
  • If any event is invalid, the answer is False . An empty log has no outstanding maintenance, so its answer is True .

Constraints

  • 0 <= len(actions) == len(times) == len(types) <= 100000
  • actions[i] is exactly "open" or "end" .
  • 0 <= times[i] <= 10^9
  • types[i] is a non-empty string of 1 to 20 lowercase English letters.
  • The answer is a single boolean and is uniquely determined by the input.

Examples

Example 1

  • Input: actions = ["open", "open", "end", "end"] , times = [1, 2, 3, 4] , types = ["oil", "brake", "brake", "oil"]
  • Output: True
  • Explanation: The oil task is open from time 1 to time 4 and the brake task from time 2 to time 3. Different types may be open together, both tasks are closed, and nothing remains open.

Example 2

  • Input: actions = ["open", "open", "end", "end"] , times = [1, 2, 3, 4] , types = ["oil", "oil", "oil", "oil"]
  • Output: False
  • Explanation: At time 2 an oil task is opened while the oil task opened at time 1 is still open, which is invalid even though the log contains as many "end" events as "open" events.

Example 3

  • Input: actions = ["end", "open", "end", "open"] , times = [9, 1, 3, 6] , types = ["tire", "tire", "tire", "tire"]
  • Output: True
  • Explanation: In time order the events are: open at 1, end at 3, open at 6, end at 9. The second tire task starts only after the first one has been closed, and both are closed by the end of the log.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...