Object-Oriented Delivery Cost and Payment Accounting System
Context
You are tasked with designing a small, in-memory service to manage delivery costs for drivers who are compensated hourly. The system needs to record individual deliveries, each defined by a start and end timestamp. Its primary functions include calculating the total accumulated cost to date, enabling the marking of accrued costs up to a specific timestamp as paid, and reporting the current total of unpaid amounts.
You must explicitly define your assumptions regarding:
- Time interval semantics (inclusive/exclusive).
- How to prorate partial hours.
- The strategy for rounding currency.
Requirements
The system must support the following operations:
- Register Driver:
RegisterDriver(driverId, hourlyRate)- Allows registering a driver with an initial hourly rate.
- Supports updating an existing driver's hourly rate.
- Record Delivery:
RecordDelivery(driverId, startTime, endTime)- Records a delivery event for a specified driver within a given time range.
- Get Total Cost:
getTotalCost() → sum over all deliveries of hourlyRate(driverId) × duration- Calculates the sum of costs for all recorded deliveries based on the driver's hourly rate at the time of the delivery and its duration.
- Pay Up To:
payUpTo(timestamp)- Marks all accrued costs up to the provided
timestampas paid. - If a delivery's duration overlaps with the
timestamp, only the portion of the delivery occurring up to thetimestampis marked as paid. This implies a logical split of the delivery's cost at thetimestamp.
- Marks all accrued costs up to the provided
- Get Total Unpaid:
getTotalUnpaid() → total remaining unpaid amount after all payUpTo calls- Returns the aggregate amount of all costs that have not yet been marked as paid.
Deliverables
Your solution should include:
- A clear class design and specification of core data structures.
- Detailed method signatures for all required operations.
- Explicit definitions for:
- Interval inclusivity/exclusivity.
- Handling of partial hours.
- Currency rounding strategy.
- A discussion covering:
- Idempotency of operations.
- Considerations for time zones.
- Numeric precision for financial calculations.
- Time and space complexity of your design.
AI interview prep
Core dilemma
Managing time-based financial calculations with partial payments and dynamic rates, ensuring accuracy and efficiency in an in-memory system, especially concerning the 'logical split' requirement for `payUpTo`.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Object-Oriented Delivery Cost and Payment Accounting System
Context
You are tasked with designing a small, in-memory service to manage delivery costs for drivers who are compensated hourly. The system needs to record individual deliveries, each defined by a start and end timestamp. Its primary functions include calculating the total accumulated cost to date, enabling the marking of accrued costs up to a specific timestamp as paid, and reporting the current total of unpaid amounts.
You must explicitly define your assumptions regarding:
- Time interval semantics (inclusive/exclusive).
- How to prorate partial hours.
- The strategy for rounding currency.
Requirements
The system must support the following operations:
- Register Driver:
RegisterDriver(driverId, hourlyRate)- Allows registering a driver with an initial hourly rate.
- Supports updating an existing driver's hourly rate.
- Record Delivery:
RecordDelivery(driverId, startTime, endTime)- Records a delivery event for a specified driver within a given time range.
- Get Total Cost:
getTotalCost() → sum over all deliveries of hourlyRate(driverId) × duration- Calculates the sum of costs for all recorded deliveries based on the driver's hourly rate at the time of the delivery and its duration.
- Pay Up To:
payUpTo(timestamp)- Marks all accrued costs up to the provided
timestampas paid. - If a delivery's duration overlaps with the
timestamp, only the portion of the delivery occurring up to thetimestampis marked as paid. This implies a logical split of the delivery's cost at thetimestamp.
- Marks all accrued costs up to the provided
- Get Total Unpaid:
getTotalUnpaid() → total remaining unpaid amount after all payUpTo calls- Returns the aggregate amount of all costs that have not yet been marked as paid.
Deliverables
Your solution should include:
- A clear class design and specification of core data structures.
- Detailed method signatures for all required operations.
- Explicit definitions for:
- Interval inclusivity/exclusivity.
- Handling of partial hours.
- Currency rounding strategy.
- A discussion covering:
- Idempotency of operations.
- Considerations for time zones.
- Numeric precision for financial calculations.
- Time and space complexity of your design.