Bills From Unordered Highway Checkpoint Logs
Updated
Problem statement
Matching arrays licenses, checkpoints, and timestamps describe unordered highway checkpoint logs. Entry i records one vehicle passing one checkpoint at one time.
Each vehicle makes one continuous trip. Sort that vehicle's records by timestamp and add the fee for each pair of consecutive checkpoints in that order. feePairs[i] is [from,to] and has fee fees[i]; every consecutive pair needed by the logs is present.
Return one string per vehicle in the format license:totalFee, ordered lexicographically by license. Vehicle/checkpoint names contain only letters and digits.
Function
billHighwayTrips(licenses: String[], checkpoints: String[], timestamps: int[], feePairs: String[][], fees: int[]) → String[]Examples
Example 1
licenses = ["A","B","A","A","B"]checkpoints = ["Y","P","X","Z","Q"]timestamps = [30,5,10,50,20]feePairs = [["X","Y"],["Y","Z"],["P","Q"]]fees = [7,4,3]return = ["A:11","B:3"]Vehicle A travels X→Y→Z for 7+4; vehicle B travels P→Q for 3.
Example 2
licenses = ["CAR9","CAR9"]checkpoints = ["EXIT","ENTRY"]timestamps = [20,10]feePairs = [["ENTRY","EXIT"]]fees = [12]return = ["CAR9:12"]The input is unordered, so timestamp sorting restores ENTRY→EXIT.
Example 3
licenses = []checkpoints = []timestamps = []feePairs = []fees = []return = []No log records produce no bills.
Constraints
0 <= licenses.length == checkpoints.length == timestamps.length <= 200000.0 <= feePairs.length == fees.length <= 200000.- Each vehicle has at least two records with distinct timestamps.
- Every fee is in
[0,10^9], and each total fits in a signed 64-bit integer. - Every needed ordered checkpoint pair appears exactly once in
feePairs.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEW
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEW
- Log Analyzer: Busiest Service in a Rolling WindowByteDance · PHONE SCREEN
- User Journey PathsWhatNot · PHONE SCREEN · ONSITE INTERVIEW
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesStripe · PHONE SCREEN
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREEN
- Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN