Reported July 2026
OnePaysimulation

Per-Segment Speeding

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 mistake that sinks a first attempt on this OnePay problem is reporting speeding segments the moment you see them. OnePay's July 2026 report of Per-Segment Speeding looks like a log parse, but it's a per-plate state machine with a trap: violations only count if the journey actually reaches EXIT. Interleaved plates, replaced ENTRYs and stray EXITs all try to leak bad indices into your answer. If you blank on the buffering logic during the live OA, StealthCoder runs invisibly as a safety net and gives you a working solution. Here's the pattern so you don't need it.

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. Each timestamp is decimal seconds with exactly three fractional digits and is interpreted exactly as integer milliseconds.
For one car, a complete journey begins with ENTRY, contains zero or more MAINROAD events, and ends with EXIT.
The array roadSegments supplies directed road metadata. Each record has four whitespace-separated fields:
fromBooth toBooth distanceMeters speedLimitKph
For every pair of consecutive records in a candidate journey, compute the exact average speed over the directed segment. A segment is speeding only when its average speed is strictly greater than speedLimitKph; equality is not speeding. Equivalently, with elapsed time in milliseconds, the segment is speeding when:
distanceMeters * 3600 > speedLimitKph * elapsedMilliseconds
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. Violations from a replaced or unfinished candidate are discarded.
Represent a speeding segment by the zero-based index in logs of its ending record. Return all such indices that belong to completed journeys in increasing input order.

Function
detectSpeedingSegments(logs: String[], roadSegments: String[]) → int[]

Examples
Example 1
logs = ["0.000 CAR1 A ENTRY","10.000 CAR2 X ENTRY","30.000 CAR1 B MAINROAD","50.000 CAR2 Y EXIT","90.000 CAR1 C EXIT"]
roadSegments = ["A B 1000 60","B C 1000 60","X Y 500 45"]
return = [2]
The A-to-B segment averages 120 km/h, above its 60 km/h limit, so index 2 is returned. The other two segments exactly equal their limits and are not speeding.
Example 2
logs = ["0.000 CAR1 A ENTRY","10.000 CAR1 B MAINROAD","11.000 CAR1 X ENTRY","31.000 CAR1 Y EXIT","40.000 CAR2 P EXIT"]
roadSegments = ["A B 1000 60","X Y 500 90"]
return = []
The first segment is speeding, but the later ENTRY replaces that unfinished candidate, so its violation is discarded. The completed X-to-Y segment exactly equals its limit, and the final EXIT is stray.
Example 3
logs = ["0.000 CAR1 A ENTRY","1.000 CAR2 X ENTRY","10.000 CAR1 B MAINROAD","11.000 CAR2 Y MAINROAD","12.000 CAR2 Z EXIT","20.000 CAR1 C EXIT"]
roadSegments = ["A B 1000 100","B C 1000 360","X Y 1000 100","Y Z 100 360"]
return = [2,3]
Both segments ending at indices 2 and 3 are speeding. CAR2 completes before CAR1, but the result is ordered by log index, so the output is [2,3].

Constraints
0 <= logs.length <= 200000
0 <= roadSegments.length <= 200000
Every log contains exactly four non-empty whitespace-separated fields and uses event type ENTRY, MAINROAD, or EXIT.
Every timestamp is nonnegative decimal seconds with exactly three fractional digits, its whole-seconds part is at most 10^9, and logs is in chronological order.
Within an active candidate journey, every record after its ENTRY has a strictly greater timestamp than the preceding record for that plate.
Every road record contains two booth IDs, an integer distanceMeters in [1, 10^9], and an integer speedLimitKph in [1, 10^6].
Each directed booth pair appears at most once in roadSegments, every segment used by an active candidate has supplied metadata, and all comparison cross-products fit in a signed 64-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a hash map keyed by plate, storing the active candidate: last booth, last timestamp in integer milliseconds, and a pending list of violating indices. ENTRY overwrites the entry, which discards the old pending list. MAINROAD with an active candidate checks the segment and appends the index if it's speeding. EXIT checks the final segment too, then flushes the pending list into a result and deletes the candidate. Stray MAINROAD or EXIT does nothing. Pitfalls: parsing timestamps as floats (split on the dot and build milliseconds as an integer), using >= instead of strict >, and forgetting to sort the output, since journeys finish out of order. Store segments in a map keyed by the string from|to. Compare distance*3600 > limit*elapsedMs in 64-bit. If the live OA gets tense, StealthCoder is the hedge. It reads the problem and hands you the code without the proctor seeing it.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Per-Segment Speeding 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 passed his OA cold and still thinks the filter is broken.

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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Per-Segment Speeding FAQ

How hard is Per-Segment Speeding really?+

Medium on paper, easy if you stay organized. There's no fancy algorithm. It's a hash map of per-plate state plus careful rules about when to discard. Most failures come from missing edge cases like replaced ENTRYs, not from complexity.

What's the main trick?+

Buffer violations per plate and only commit them on EXIT. An ENTRY wipes the buffer, and an unfinished journey never commits. Then sort the final indices, because journeys complete in a different order than their log positions.

How do I avoid floating point errors on timestamps?+

Never parse them as doubles. Split the string on the dot, multiply the whole seconds by 1000, and add the three fractional digits as an integer. Then use the integer cross-product inequality from the statement, distance*3600 > limit*elapsedMs.

Does equality count as speeding?+

No. The segment must be strictly greater than the limit. Example 1 shows two segments exactly at the limit that are excluded. Use a strict greater-than in the comparison, and don't round anywhere.

How do I prepare for this in 48 hours?+

Write the state machine once from scratch and run the three examples by hand. Test a replaced ENTRY, a stray EXIT, and two interleaved plates. Practice parsing strings fast, since 200000 records means a linear pass with map lookups is expected.

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