Count Completed Trips
Reported by candidates from LinkedIn's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
LinkedIn asked this in April 2026: track vehicle logs and count how many plates complete the full entry -> road -> exit sequence in order. You're not building a complex state machine. You're just watching for the specific pattern and incrementing a counter. Most candidates over-engineer this by trying to track state across multiple plates simultaneously. The trick is simpler: one pass through the logs, track each plate's last known state, and only increment when you see exit after road after entry. StealthCoder will spot the pattern instantly if you blank on the state transitions.
The problem
You are given vehicle event logs in chronological order. Each log contains a license plate and one of three event types: entry, road, or exit. A completed trip is counted when the same plate appears in order as entry -> road -> exit. Count the total number of completed trips across all plates. Function Description Complete the function countCompletedTrips in the editor below. countCompletedTrips has the following parameter: Returns Plate A completes one valid entry -> road -> exit sequence. Plate A completes one trip. Plate B does not, because it never reaches the road event before exiting.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is state tracking per plate. Create a hash table keyed by license plate, storing the last event type seen for each plate. As you iterate through logs in order, update the state for each plate. When you see entry, set state to 'entry'. When you see road, only count it if the plate is in 'entry' state, then set state to 'road'. When you see exit, only count the trip if state is 'road', then reset. The catch: plates can cycle through the sequence multiple times, so you must reset the state after a completed trip so the same plate can register again. Walk through the example: Plate A goes entry (state = entry), then road (state = road), then exit (trip counted, state reset). Plate B goes entry, exit without ever hitting road (no trip). This is a hash-table plus simulation problem, not dynamic programming or greedy.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Count Completed Trips cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass LinkedIn's OA.
LinkedIn reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Completed Trips FAQ
Do I need to validate event order or handle duplicate events?+
The input is already in chronological order. The problem doesn't mention duplicates or invalid sequences, so assume clean data. Your job is to count valid sequences, not validate. Read the problem statement as gospel.
What happens if a plate does entry -> road -> road -> exit?+
Only one trip counted. Once you see road after entry, you're waiting for exit. A second road event doesn't change the state. The exit after road triggers the count and resets the state.
Can the same plate appear in multiple separate trips?+
Yes. After you count a trip (entry -> road -> exit), reset that plate's state to nothing. The same plate can later start a new entry and cycle again. Each completed sequence is one trip.
How do I initialize the state for a plate I've never seen?+
Don't pre-initialize. Use a hash table and check if the plate exists. When you see the first event for a plate, that's usually entry. If it's not entry, you can't form a valid trip from that starting point, so you're waiting for the next entry.
Is this problem hard? What's the real trick?+
It's a medium difficulty state machine. The trick is not overthinking it. One hash table, one loop, track the last state per plate, and reset after counting. Most candidates fail by trying to track all transitions globally instead of per-plate.