FastPrepCount Complete Toll Journeys
Problems/Count Complete Toll Journeys

Count Complete Toll Journeys

OnePay logoOnePay● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a OnePay phone screen for a full-time role. The report defines toll logs for each car that are mixed together, and the pattern of a complete journey. It leaves out what happens with a malformed sequence and the input limits. We only ask for the count. The fare and speed follow-ups are not part of this task.

Our version is about 96% the same as the reported question.

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.

More OnePay Phone Screen questions

  • Device Registry OperationsPHONE SCREEN · Seen Sep 2026
  • Per-Segment SpeedingPHONE SCREEN · Seen Jul 2026
  • Toll Journey FaresPHONE SCREEN · Seen Jul 2026
  • Parse a Numeric Toll-Log TimestampPHONE SCREEN · Seen Mar 2026

Similar questions at other companies

  • Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
  • SimpleRDD Word CountDatologyAI · PHONE SCREEN
  • Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
  • Wordle Feedback with Duplicate LettersScale AI · PHONE SCREENScale AI interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • String Interpolation with a Missing-Value ModeMongoDB · PHONE SCREENMongoDB interview questions
  • Dasher Pay with Store Waits and Peak HoursDoorDash · PHONE SCREENDoorDash interview questions
  • Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
  • Fixed-Order Task Run Time With CooldownWaymo · PHONE SCREENWaymo interview questions
All OnePay interview questionsSee OnePay hiring insights
Saved
class Solution {
    public int countCompleteJourneys(String[] logs) {
        // Write your code here.
    }
}
Checking account…