Delivery Cost Tracker with Effective-Dated Rates
Updated
Problem statement
Build a tracker for delivery costs. Each driver has an hourly rate, and that rate can change starting at a given time. Process the rows of operations in order. Return one formatted cost for every query, in query order.
Operation Format
Driver IDs, delivery IDs and timestamps are given as decimal strings. Hourly rates are in USD, given as decimal strings with at most two digits after the decimal point.
["ADD_DRIVER", driverId, hourlyRate]adds a driver whose first rate takes effect at timestamp0.["UPDATE_DRIVER_RATE", driverId, newRate, effectiveTime]adds a new rate version for the driver. If a later update uses the same effective time, it replaces that version for deliveries recorded after it.["RECORD_DELIVERY", deliveryId, driverId, startTime, endTime]records a delivery. Delivery IDs are unique across the whole system. The delivery is ignored if its ID was already accepted, or if it lasts more than10800seconds. An ignored delivery does not claim its ID, so a later delivery can still use that ID.["GET_TOTAL_COST"]returns the total cost of all accepted deliveries.["PAY_UP_TO", payTime]marks every delivery recorded so far withendTime <= payTimeas paid. Calling it again never pays a delivery twice.["GET_UNPAID_COST"]returns the total cost of all deliveries that are unpaid right now.
Cost Rules
- When a delivery is recorded, look at the rate versions added so far. Use the one with the latest effective time that is not after the delivery's
startTime. Use that rate for the whole delivery, even if a different rate takes effect partway through it. - The cost is
hourlyRate * (endTime - startTime) / 3600. Accepted deliveries that overlap in time are each billed on their own. - Later rate updates never change the cost of a delivery that is already recorded.
- Keep every fraction of a cent while adding up costs. Round only the full total that a query asks for. Round it to the nearest cent, round an exact half cent up, and show exactly two digits after the decimal point.
- A delivery recorded after an earlier
PAY_UP_TOcall starts out unpaid, even if it ended before that call's timestamp. A later payment call can pay it.
Interviewer Follow-ups
This is an AI-enabled coding round with no starter template, so you define the classes and functions yourself. Be ready to:
- walk through the overall design and data structures before the code is generated, including which timestamps you use and how a rate update is applied;
- explain why the code is implemented the way it is;
- write their own test cases and use them to check the code;
- look up and use a driver's historical rates, not just the current one;
- explain why storing money as a float and rounding to two decimal places is not enough, and how to keep costs exact;
- make
GET_TOTAL_COSTrun in O(1) time instead of O(n).
These follow-ups are for discussion. The tests check only the returned costs.
Function
trackDeliveryCostsWithRateHistory(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD_DRIVER","1","12.00"],["RECORD_DELIVERY","101","1","0","1800"],["UPDATE_DRIVER_RATE","1","18.00","1000"],["RECORD_DELIVERY","102","1","1000","2000"],["GET_TOTAL_COST"],["GET_UNPAID_COST"]]return = ["11.00","11.00"]The first delivery costs $6.00 at the rate in place when it was recorded. The second starts when the new rate takes effect, so it costs $5.00. Neither has been paid, so the total and the unpaid cost are the same.
Example 2
operations = [["ADD_DRIVER","7","24.00"],["UPDATE_DRIVER_RATE","7","30.00","3600"],["RECORD_DELIVERY","201","7","0","1800"],["RECORD_DELIVERY","202","7","3600","7200"],["GET_TOTAL_COST"],["PAY_UP_TO","2000"],["GET_UNPAID_COST"]]return = ["42.00","30.00"]The deliveries cost $12.00 and $30.00. Paying through timestamp 2000 pays only the first, leaving $30.00 unpaid.
Example 3
operations = [["ADD_DRIVER","3","10.00"],["UPDATE_DRIVER_RATE","3","20.00","100"],["UPDATE_DRIVER_RATE","3","30.00","100"],["RECORD_DELIVERY","301","3","100","460"],["GET_TOTAL_COST"]]return = ["3.00"]The later rate update at timestamp 100 replaces the earlier one. The six-minute delivery therefore costs $3.00.
Example 4
operations = [["ADD_DRIVER","4","27.27"],["RECORD_DELIVERY","401","4","0","3000"],["RECORD_DELIVERY","402","4","3000","4000"],["GET_TOTAL_COST"],["RECORD_DELIVERY","401","4","5000","6000"],["RECORD_DELIVERY","403","4","0","10801"],["GET_TOTAL_COST"]]return = ["30.30","30.30"]The first two deliveries are accepted and cost $22.725 and $7.575. Their exact sum is $30.300, which rounds to $30.30. After that, the repeated ID and the delivery lasting 10801 seconds are both ignored, so the second total does not change.
Constraints
1 <= operations.length <= 100000; every operation has one documented shape.- Driver and delivery identifiers are integers from
1through10^9, encoded as decimal strings. Each driver is registered exactly once, before any operation referencing it. - Hourly rates range from
0.01through1000000.00USD and have at most two fractional digits. 0 <= effectiveTime, startTime, endTime, payTime <= 10^9andstartTime < endTime. Deliveries longer than10800seconds are ignored.- Rate updates may arrive in any effective-time order. The initial rate is effective from timestamp
0. - The sum of
hourlyRateInCents * durationInSecondsover accepted deliveries fits in signed 64-bit arithmetic.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
- Delivery Cost TrackerPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Range ModuleWalmart · PHONE SCREENWalmart interview questions
- Consistent-Hash Packet RouterAmazon · PHONE SCREEN
- Interview Slot BookingTrueFoundry · PHONE SCREEN
- Banking System with Historical SnapshotsCoinbase · OACoinbase interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Key-Value Store with Hit CounterDatabricks · ONSITE INTERVIEWDatabricks interview questions
- Split Tender Part 4 - RefundsStripe · OA · PHONE SCREENStripe interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Dynamic Least-Loaded Job DispatcherCresta · PHONE SCREENCresta interview questions
- Out-of-Order Loan LedgerValon · PHONE SCREEN
Interview reports that mention this question
- Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)
- Rippling SWE Interviews, No Level: 156 Experiences (Part 1 of 6)
- Rippling Rules and Task Screens: 22 Experiences (Part 3 of 12)
- Rippling Delivery Cost Screen: 21 Experiences (Part 2 of 12)
- Rippling AI Coding Interview, Experienced SWE: 9 Experiences
- Rippling Full-Time SWE Interviews: 224 Experiences (Part 1 of 12)