This question evaluates stateful event-stream processing and per-entity state management, testing the ability to track and reconcile time-ordered sensor events while handling edge cases like unmatched or spurious events.
You are given a time-ordered list of highway sensor logs. Each log entry contains:
timestamp
(integer; strictly increasing)
sensor_type
(one of
"ENTRY"
,
"EXIT"
,
"CHECKPOINT"
)
car_id
(string)
A journey is defined as: for the same car_id, an ENTRY event followed later by an EXIT event. CHECKPOINT events may occur in between but do not affect the definition.
A car may make multiple journeys over time (e.g., ENTRY ... EXIT ... ENTRY ... EXIT). If a car has an ENTRY without a subsequent EXIT by the end of the logs, that partial journey does not count. If an EXIT occurs when the car is not currently in an active journey (i.e., there was no unmatched prior ENTRY), ignore it.
Write a function that returns the total number of completed journeys across all cars.
Example:
Logs:
Result: 2 (A completes 1 journey at t=3; B completes 1 journey at t=7).