Delivery Cost Tracker
Updated
Problem statement
Build a cost tracker for delivery drivers. Each driver has a fixed hourly rate, and every recorded delivery contributes to the company's total delivery cost.
Operation Format
Process the rows of operations in order. Return one string for every query operation, in query order.
["ADD_DRIVER", driverId, hourlyRate]: Add a driver whose hourly rate is a decimal USD string with at most two fractional digits. Driver IDs are unique.["RECORD_DELIVERY", driverId, startTime, endTime]: Record a delivery interval using integer Unix timestamps in seconds. The driver exists,startTime < endTime, and the interval lasts at most three hours.["GET_TOTAL_COST"]: Return the total cost of all recorded deliveries.["PAY_UP_TO", payTime]: Mark every delivery withendTime <= payTimeas paid.["GET_UNPAID_COST"]: Return the total cost of all currently unpaid deliveries.
Cost Rules
- A delivery's cost is
hourlyRate * (endTime - startTime) / 3600. - Overlapping deliveries are paid independently, even when they belong to the same driver.
- Format every returned cost with exactly two digits after the decimal point.
- Every judged delivery produces an exact cent value, so no additional rounding rule is needed.
Interviewer follow-ups
Reports describe the task growing in stages: first maintain total cost, then support paying all completed deliveries up to a timestamp and querying unpaid cost. A later follow-up asks for the maximum number of simultaneously active drivers during the previous 24 hours. Interviewers also emphasized exact decimal handling for financial values.
Function
trackDeliveryCosts(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD_DRIVER","alice","10.00"],["RECORD_DELIVERY","alice","0","5400"],["GET_TOTAL_COST"],["GET_UNPAID_COST"],["PAY_UP_TO","5400"],["GET_UNPAID_COST"]]return = ["15.00","15.00","0.00"]A 90-minute delivery at $10 per hour costs $15. It remains unpaid until PAY_UP_TO 5400.
Example 2
operations = [["ADD_DRIVER","a","18.00"],["ADD_DRIVER","b","24.00"],["RECORD_DELIVERY","a","100","1300"],["RECORD_DELIVERY","b","500","2300"],["GET_TOTAL_COST"],["PAY_UP_TO","1500"],["GET_UNPAID_COST"]]return = ["18.00","12.00"]The overlapping deliveries cost $6 and $12 independently. Only the first has ended by timestamp 1500.
Constraints
1 <= operations.length <= 100000- Timestamps are integer seconds.
- Every judged delivery cost is an exact number of cents.
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
- Delivery Cost Tracker with Effective-Dated RatesPHONE 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
Similar questions at other companies
- Memory AllocatorOpenAI · PHONE SCREENOpenAI interview questions
- In-Memory Meeting Room ManagerRunloop · PHONE SCREEN
- Calendar Event System with Pagination and IntersectionLead Bank · ONSITE INTERVIEWLead Bank interview questions
- Worker Management with Promotions and Double-Paid TimeInstacart · ONSITE INTERVIEWInstacart interview questions
- Range ModuleWalmart · PHONE SCREENWalmart interview questions
- Worker Management (Promotion Track), Part 4: Full-Shift Double PayAirbnb · OAAirbnb interview questions
- Worker Management, Part 4: Double-Paid IntervalsAnthropic · OAAnthropic interview questions
- Priority Ad Rotation with Show LimitsAmazon · ONSITE INTERVIEW
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Recipe Rating ServiceNubank · PHONE SCREEN
Interview reports that mention this question
- Rippling Design Rounds and Onsites: 17 Experiences (Part 3 of 3)
- Rippling Phone Coding Screens: 14 Experiences (Part 2 of 3)
- Rippling SWE Screens and Loops: 31 Experiences (Part 1 of 3)
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)