This one was more involved than I expected for a phone screen.
Start by clarifying requirements and edge cases with the interviewer, then define clean data classes (e.g., using dataclasses) to model the inputs and payout components. Write a modular function that computes each component (base, mileage, time, tips, peak multiplier, guaranteed minimum) and combines them with proper rounding and validation. Test with representative and edge cases to ensure correctness.
Pro tip: Mention that you would use integer cents for all monetary calculations to avoid floating-point errors, and discuss how you'd handle rounding consistently (e.g., round half up) to align with business rules.
Ask questions to understand the exact payout formula, precedence of rules (e.g., peak multiplier applies before or after tips), and edge cases like negative values, zero distances, or missing tips.
Define immutable data classes for inputs (e.g., DeliveryInput) and outputs (e.g., PayoutBreakdown) using appropriate types (e.g., Decimal or int for money) and validation in constructors.
Write a function that computes each component step by step: base pay, mileage pay, time pay, tips, apply peak multiplier, and finally enforce the guaranteed minimum. Use helper functions for clarity.
Add checks for invalid inputs (negative rates, null tips), handle zero values gracefully, and ensure rounding is consistent. Consider using exceptions or default values as appropriate.
Walk through test cases (normal, edge, and error cases) and discuss trade-offs like using Decimal vs. int, immutability vs. flexibility, and extensibility for future rules.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.