</>OfferRetriever
DashboardDiscuss
NEW

Spring Hire Sale

Limited Time Deal: Unlock all premium questions for over 30% off

$10.42$7.08

08

:

04

:

53

:

48

Get this deal
Back to Dashboard

[AI Enabled Coding] Food Delivery Company

Medium

Question

You are building a driver payment system for a food delivery company. The accounting team needs to track how much money is owed to drivers and display this on a live dashboard.


Part 1 — Driver Sign-up and Delivery Recording

Implement the following functions:

sign_up_driver(driver_id, hourly_rate)

  • Registers a new driver with their unique ID
  • Associates the driver with an hourly rate in USD

record_delivery(driver_id, start_time, end_time)

  • Records a completed delivery
  • Start and end times have at least second-level precision
  • Drivers are paid their full hourly rate for each delivery (regardless of duration)

total_cost()

  • Returns the total cost of all deliveries completed across all drivers

Note: The choice of time format is an important design decision to discuss before implementation.

Example 1 — Basic Flow

Input:

sign_up_driver("driver_1", 20.0)
sign_up_driver("driver_2", 25.0)

record_delivery("driver_1", "2024-01-15T10:00:00", "2024-01-15T10:30:00")
record_delivery("driver_1", "2024-01-15T11:00:00", "2024-01-15T11:45:00")
record_delivery("driver_2", "2024-01-15T09:00:00", "2024-01-15T09:15:00")

total_cost()

Output:

65.0

Explanation:

  • Driver 1: 2 deliveries × $20.00 = $40.00
  • Driver 2: 1 delivery × $25.00 = $25.00
  • Total: $40.00 + $25.00 = $65.00

Example 2 — Multiple Drivers

Input:

sign_up_driver("driver_a", 15.0)
sign_up_driver("driver_b", 30.0)
sign_up_driver("driver_c", 22.5)

record_delivery("driver_a", "2024-01-15T08:00:00", "2024-01-15T08:30:00")
record_delivery("driver_b", "2024-01-15T09:00:00", "2024-01-15T09:20:00")
record_delivery("driver_c", "2024-01-15T10:00:00", "2024-01-15T10:45:00")
record_delivery("driver_a", "2024-01-15T11:00:00", "2024-01-15T11:15:00")

total_cost()

Output:

82.5

Explanation:

  • Driver A: 2 deliveries × $15.00 = $30.00
  • Driver B: 1 delivery × $30.00 = $30.00
  • Driver C: 1 delivery × $22.50 = $22.50
  • Total: $30.00 + $30.00 + $22.50 = $82.50

Part 2 — Payout Tracking

...