Reported July 2026
OnePayhash table

Count Complete Toll Journeys

Reported by candidates from OnePay's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live OnePay OA. Under 2s to a working solution.
Founder's read

The OnePay OA reported in July 2026 hides a simple problem behind a messy log format, and the first-attempt mistake is treating the logs like one global stream. Count Complete Toll Journeys gives you interleaved toll records for many license plates, and you count finished ENTRY to EXIT trips. It's a per-key state machine with a hash map. The rules are short, but one edge case trips people who skim. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution while you recover.

The problem

You are given a chronological array of highway toll records logs. Each record has four whitespace-separated fields:
timestamp licensePlate boothId eventType
The eventType is ENTRY, MAINROAD, or EXIT. Records for different license plates may be interleaved.
For one car, a complete journey begins with ENTRY, contains zero or more MAINROAD events, and ends with EXIT.
For this exercise, assume an ENTRY starts a new candidate journey for that plate and replaces any unfinished candidate. A MAINROAD event extends an active candidate and is ignored otherwise. An EXIT completes and closes an active candidate and is ignored otherwise.
Return the total number of complete journeys across all license plates.

Function
countCompleteJourneys(logs: String[]) → int

Examples
Example 1
logs = ["90750.191 JOX304 250E ENTRY","91081.684 JOX304 260E MAINROAD","91082.101 THX138 110E ENTRY","91483.251 JOX304 270E MAINROAD","91873.920 THX138 120E MAINROAD","91874.493 JOX304 280E EXIT","91982.102 THX138 290E EXIT","92301.302 THX138 300E ENTRY","92371.302 THX138 310E EXIT"]
return = 3
JOX304 completes one journey. THX138 completes one journey ending at timestamp 91982.102 and another ending at 92371.302, for a total of 3.
Example 2
logs = ["1.000 CAR1 A MAINROAD","2.000 CAR1 B EXIT","3.000 CAR2 C ENTRY","4.000 CAR2 D MAINROAD"]
return = 0
The first two records have no preceding entry for CAR1. The CAR2 entry never reaches an exit, so no complete journey is counted.
Example 3
logs = ["1.000 CAR1 A ENTRY","2.000 CAR1 B ENTRY","3.000 CAR1 C MAINROAD","4.000 CAR1 D EXIT","5.000 CAR1 E EXIT"]
return = 1
The second entry replaces the unfinished CAR1 candidate. Its following main-road record and exit complete one journey. The final exit has no active candidate.

Constraints
0 <= logs.length <= 200000
Every record contains exactly four non-empty whitespace-separated fields.
The first field is a timestamp, and logs is in chronological order.
The second and third fields are a license plate and booth ID.
The fourth field is ENTRY, MAINROAD, or EXIT.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is tracking one boolean per plate: is there an active candidate journey. Use a hash map from plate to active state. On ENTRY, set active to true, even if it was already true, because a new entry replaces the unfinished one and never counts twice. On MAINROAD, do nothing, since it only extends an active candidate and the count doesn't change. On EXIT, if active, increment the answer and set active to false. Otherwise ignore it. The common pitfall is counting ENTRY events or pairing the first ENTRY with the last EXIT, which breaks Example 3 where the answer is 1, not 2. Another pitfall is a single global flag that lets plates interfere. Parsing is a split on whitespace, and you only need fields two and four. It's O(n) time with up to 200000 records, so no sorting is needed. StealthCoder is your hedge in the live OA if the state rules slip your mind under pressure.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Count Complete Toll Journeys 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass OnePay's OA.

OnePay reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Complete Toll Journeys FAQ

How hard is Count Complete Toll Journeys really?+

Easy. It's a single pass with a hash map and three branches. The difficulty is reading the rules carefully, especially that a repeated ENTRY replaces the candidate instead of stacking. If you code the three event types exactly as written, it passes.

What's the trick to this OnePay problem?+

Keep independent state per license plate. A map from plate to a boolean works. ENTRY sets it true, EXIT increments the count only if it's true and then resets it, and MAINROAD is a no-op. That's the entire solution.

Why is Example 3 only 1 and not 2?+

The second ENTRY replaces the unfinished candidate from the first, so there's only one active journey. The first EXIT closes it and counts once. The final EXIT finds no active candidate and is ignored, so the total stays 1.

Do I need to sort or group the logs first?+

No. The logs are already chronological, so one pass is enough. Interleaving across plates is handled by the map, since each plate's state is independent. Sorting would only add cost and risk.

How do I prepare for this in 48 hours?+

Practice per-key state machines with a hash map and string splitting. Write this one from scratch twice and test your own edge cases: EXIT with no entry, double ENTRY, MAINROAD alone, and an empty array returning 0.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with OnePay.

OA at OnePay?
Invisible during screen share
Get it