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:
-
(1, "ENTRY", "A")
-
(2, "CHECKPOINT", "A")
-
(3, "EXIT", "A")
-
(4, "EXIT", "B")
-
(5, "ENTRY", "A")
-
(6, "ENTRY", "B")
-
(7, "EXIT", "B")
Result: 2 (A completes 1 journey at t=3; B completes 1 journey at t=7).