FastPrepToll Journey Fares
Problems/Toll Journey Fares

Toll Journey Fares

OnePay logoOnePay● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a OnePay phone screen for a full-time role. The report names working out fares over toll-journey logs that are mixed together. It leaves out the price model and the exact result. Here the task is a sum over segments.

Our version is about 70% 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.

The array tollRates supplies directed segment prices. Each rate record has three whitespace-separated fields:

fromBooth toBooth fareCents

For this exercise, assume a completed journey costs the sum of the fares for every consecutive directed booth pair from its ENTRY through its EXIT.

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. Unfinished candidates produce no fare.

Return one fare in cents for every completed journey, ordered by the EXIT records that complete the journeys.

Function

calculateJourneyFares(logs: String[], tollRates: String[]) → long[]

Examples

Example 1

logs = ["0.000 CAR1 A ENTRY","1.000 CAR2 B ENTRY","2.000 CAR1 C MAINROAD","3.000 CAR2 D EXIT","4.000 CAR1 D EXIT","5.000 CAR1 A ENTRY","6.000 CAR1 C EXIT"]tollRates = ["A C 125","C D 200","B D 90"]return = [90,325,125]

CAR2 completes first with fare 90. The first CAR1 journey costs 125 + 200 = 325, and its second journey costs 125.

Example 2

logs = ["0.000 CAR1 A MAINROAD","1.000 CAR1 B EXIT","2.000 CAR1 A ENTRY","3.000 CAR1 B MAINROAD","4.000 CAR1 C ENTRY","5.000 CAR1 D EXIT","6.000 CAR2 E ENTRY"]tollRates = ["A B 50","C D 70"]return = [70]

The stray records are ignored. The second ENTRY for CAR1 discards its earlier unfinished candidate, so only the direct C-to-D journey completes. CAR2 never exits.

Example 3

logs = ["0.000 X A ENTRY","1.000 X B EXIT","2.000 Y B ENTRY","3.000 Y A EXIT"]tollRates = ["A B 40","B A 75"]return = [40,75]

A direct ENTRY-to-EXIT journey has one priced segment. Rates are directed, so A-to-B costs 40 while B-to-A costs 75.

Constraints

  • 0 <= logs.length <= 200000
  • 0 <= tollRates.length <= 200000
  • Every log contains exactly four non-empty whitespace-separated fields and uses event type ENTRY, MAINROAD, or EXIT.
  • The first log field is a timestamp, and logs is in chronological order.
  • Every rate contains exactly two booth IDs followed by an integer fareCents with 0 <= fareCents <= 10^9.
  • Each directed booth pair appears at most once in tollRates, and every segment used by an active candidate has a supplied rate.
  • Every completed journey fare fits in a signed 64-bit integer.

More OnePay Phone Screen questions

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

Similar questions at other companies

  • Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe 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
  • Character Counts with Retried Remote WorkersCoalition · PHONE SCREEN
  • Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Risk-Priority Detection StoreCrowdstrike · PHONE SCREENCrowdstrike interview questions
All OnePay interview questionsSee OnePay hiring insights
Saved
class Solution {
    public long[] calculateJourneyFares(String[] logs, String[] tollRates) {
        // Write your code here.
    }
}
Checking account…