Here is the complete problem statement, examples, constraints, hints, and solution for the "Driver Payment System" interview question from Doordash on ShowOffer.io:
Problem Statement: DoorDash has a new driver payment system that calculates driver earnings based on the following rules:
Write a function calculate_driver_earnings that takes in the following parameters:
base_pay: Base pay per delivery (default = $30)bonus: Bonus per delivery if completed within 30 minutes (default = $10)surge_pay: Surge pay per delivery during peak hours (default = $5)delivery_time: Time taken to complete the delivery in minutesis_peak_hours: Boolean indicating if the delivery was completed during peak hourstip: Tip amount for the deliveryThe function should return the total driver earnings, which is the sum of base pay, bonus, surge pay, and tip.
Examples:
calculate_driver_earnings(delivery_time=25, is_peak_hours=True, tip=5)
calculate_driver_earnings(delivery_time=45, is_peak_hours=False, tip=10)
Constraints:
base_pay, bonus, surge_pay, and tip are non-negative numbers.delivery_time is a non-negative integer.is_peak_hours is a boolean value.Hints:
+ operator to sum up the different components of the driver earnings.Solution: `python def calculate_driver_earnings(base_pay=30, bonus=10, surge_pay=5, delivery_time=0, is_peak_hours=False, tip=0): total_earnings = base_pay + tip
if delivery_time <= 30:
total_earnings += bonus
if is_peak_hours:
total_earnings += surge_pay
return total_earnings
`
This function takes in the required parameters and calculates the total driver earnings based on the given rules. It uses conditional statements to check for bonus and surge pay eligibility and adds up the different components to get the final earnings.