KatInterview

Calculate Ride Service Economics and Peak Pricing

Math & Bit ManipulationAuto-graded · 17 test cases
MediumAuto-gradedMath & Bit Manipulationunit-economicscapacity-planningprofit-calculation

Last updated

Tests unit economics, capacity planning, and dynamic pricing calculations for a transportation service with fixed driver costs and variable demand.

You're analyzing the economics of a transportation service. The service operates with drivers who are paid a fixed daily wage and work a set number of hours per day. Each driver can complete a maximum number of rides per hour based on service time and geography.

Write a function that calculates key financial metrics and determines optimal peak pricing.

Inputs

Your function receives nine parameters:

  1. daily_rides (int): Total number of rides completed per day
  2. base_price (float): Price charged per ride in dollars
  3. driver_daily_pay (float): Fixed amount paid to each driver per day
  4. max_rides_per_driver_per_hour (int): Maximum rides one driver can complete in one hour
  5. driver_hours (int): Number of hours each driver works per day
  6. fixed_daily_cost (float): Daily fixed operating costs (technology, overhead, etc.)
  7. non_peak_rides (int): Number of rides during off-peak hours
  8. peak_rides (int): Number of rides during peak hours
  9. non_peak_price (float): Price per ride during off-peak hours

Note: daily_rides equals non_peak_rides + peak_rides in all test cases.

Output

Return a dictionary with exactly five keys (all float values):

  • "drivers": Minimum number of drivers needed to handle daily_rides (round up if fractional)
  • "daily_revenue": Total revenue from all rides at base_price
  • "driver_cost": Total cost of paying all drivers
  • "daily_profit": Revenue minus driver cost minus fixed cost
  • "target_peak_price": Price per peak ride that would achieve the same daily_profit if non-peak rides are priced at non_peak_price and the same number of drivers is employed

Important Rules

  • Drivers are paid their full daily wage regardless of how many rides they complete
  • The number of drivers must be sufficient to handle the total daily_rides given each driver's capacity
  • When calculating target_peak_price, assume the same number of drivers is needed (based on total daily_rides)
  • If peak_rides is zero, set target_peak_price to 0.0
  • Round up fractional driver counts (you can't hire 2.3 drivers)

Constraints

  • 0 ≤ daily_rides ≤ 10,000
  • 0 < base_price ≤ 100
  • 0 < driver_daily_pay ≤ 2,000
  • 1 ≤ max_rides_per_driver_per_hour ≤ 10
  • 1 ≤ driver_hours ≤ 24
  • 0 ≤ fixed_daily_cost ≤ 100,000
  • 0 ≤ non_peak_rides, peak_rides ≤ 10,000
  • 0 < non_peak_price ≤ 100
  • daily_rides = non_peak_rides + peak_rides

Examples

Example 1

Input: calculate_ride_service_metrics(2400, 30, 700, 5, 8, 10000, 800, 1600, 30)

Output: {'drivers': 60, 'daily_revenue': 72000, 'driver_cost': 42000, 'daily_profit': 20000, 'target_peak_price': 30}

Example 2

Input: calculate_ride_service_metrics(100, 25, 500, 5, 8, 1000, 40, 60, 25)

Output: {'drivers': 3, 'daily_revenue': 2500, 'driver_cost': 1500, 'daily_profit': 0, 'target_peak_price': 25}

Example 3

Input: calculate_ride_service_metrics(0, 30, 700, 5, 8, 10000, 0, 0, 30)

Output: {'drivers': 0, 'daily_revenue': 0, 'driver_cost': 0, 'daily_profit': -10000, 'target_peak_price': 0}

Hints

Hint 1

Calculate each driver's total daily capacity by multiplying their hourly ride limit by their working hours

Hint 2

The number of drivers needed is determined by dividing total rides by capacity per driver, rounding up to ensure all rides can be served

Hint 3

To find the target peak price, set up an equation where total revenue (non-peak + peak) minus costs equals the original daily profit