PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in implementing business billing rules, time and distance-based fee calculations, timestamp arithmetic, numerical rounding, and efficient aggregation for payouts; it falls under the Coding & Algorithms domain with emphasis on billing logic, time-series aggregation, and data processing.

  • medium
  • Rippling
  • Coding & Algorithms
  • Software Engineer

Implement Food Delivery Billing

Company: Rippling

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are implementing billing logic for a food-delivery platform. Each completed delivery record contains: - `order_id` - `driver_id` - `requested_at` — when the customer placed the order - `picked_up_at` — when the driver picked up the food - `delivered_at` — when the order was delivered - `distance_km` Use the following rules: **Customer delivery charge** - Base fee: `$2.00` - Distance fee: `$1.20 * distance_km` - Time fee: `$0.25` per minute from `picked_up_at` to `delivered_at` - Peak-hour multiplier: if `requested_at` falls in either `11:00-13:00` or `18:00-20:00`, multiply the total by `1.5` - Return the final value rounded to the nearest cent **Driver payout** - Fixed completion bonus: `$3.00` - Distance payout: `$0.80 * distance_km` - Time payout: `$0.20` per minute from `picked_up_at` to `delivered_at` - A delivery becomes payable at `delivered_at` Implement the following: 1. A function to compute the customer delivery charge for a single order. 2. A function `total_payout_at(timestamp, deliveries)` that returns the total amount owed to all drivers for deliveries with `delivered_at <= timestamp`. 3. Follow-up: explain how you would support a very large number of deliveries and many payout queries at arbitrary timestamps more efficiently than scanning the full list each time.

Quick Answer: This question evaluates proficiency in implementing business billing rules, time and distance-based fee calculations, timestamp arithmetic, numerical rounding, and efficient aggregation for payouts; it falls under the Coding & Algorithms domain with emphasis on billing logic, time-series aggregation, and data processing.

Part 1: Compute Customer Delivery Charge for One Order

You are given one completed food-delivery order. Compute the customer delivery charge using these rules: - Base fee: $2.00 - Distance fee: $1.20 * distance_km - Time fee: $0.25 per minute from picked_up_at to delivered_at - Peak-hour multiplier: if requested_at falls in 11:00-13:00 or 18:00-20:00, multiply the total by 1.5 Return the final charge rounded to the nearest cent. Treat peak windows as start-inclusive and end-exclusive: [11:00, 13:00) and [18:00, 20:00).

Constraints

  • All timestamps use the format 'YYYY-MM-DD HH:MM' and are in the same timezone.
  • 0 <= distance_km <= 1000
  • requested_at <= picked_up_at <= delivered_at
  • All timestamps are exact to the minute.

Examples

Input: ({'requested_at': '2024-05-01 10:30', 'picked_up_at': '2024-05-01 10:40', 'delivered_at': '2024-05-01 11:00', 'distance_km': 5.0},)

Expected Output: 13.0

Explanation: Base 2.00 + distance 6.00 + time 5.00 = 13.00. Requested time is not peak.

Input: ({'requested_at': '2024-05-01 11:15', 'picked_up_at': '2024-05-01 11:20', 'delivered_at': '2024-05-01 11:50', 'distance_km': 3.5},)

Expected Output: 20.55

Explanation: Before multiplier: 2.00 + 4.20 + 7.50 = 13.70. Lunch peak applies, so 13.70 * 1.5 = 20.55.

Input: ({'requested_at': '2024-05-01 13:00', 'picked_up_at': '2024-05-01 13:05', 'delivered_at': '2024-05-01 13:25', 'distance_km': 2.0},)

Expected Output: 9.4

Explanation: 13:00 is outside the peak window because the end is exclusive. Total = 2.00 + 2.40 + 5.00 = 9.40.

Input: ({'requested_at': '2024-05-01 18:00', 'picked_up_at': '2024-05-01 18:10', 'delivered_at': '2024-05-01 18:10', 'distance_km': 0.0},)

Expected Output: 3.0

Explanation: Zero distance and zero delivery time. Base fee 2.00 gets multiplied by peak factor 1.5, giving 3.00.

Hints

  1. First compute the delivery duration in minutes using picked_up_at and delivered_at.
  2. Check the peak-hour multiplier using only requested_at, not pickup or delivery time.

Part 2: Total Driver Payout Owed Up to a Timestamp

You are given a timestamp and a list of completed deliveries. A delivery becomes payable at delivered_at. Compute the total amount owed to all drivers for deliveries with delivered_at <= timestamp. For each payable delivery: - Fixed completion bonus: $3.00 - Distance payout: $0.80 * distance_km - Time payout: $0.20 per minute from picked_up_at to delivered_at Return the total payout rounded to the nearest cent.

Constraints

  • 0 <= len(deliveries) <= 100000
  • All timestamps use the format 'YYYY-MM-DD HH:MM' and are in the same timezone.
  • For every delivery, picked_up_at <= delivered_at.
  • All timestamps are exact to the minute.

Examples

Input: ('2024-05-01 12:00', [{'picked_up_at': '2024-05-01 10:00', 'delivered_at': '2024-05-01 10:20', 'distance_km': 5.0}, {'picked_up_at': '2024-05-01 11:00', 'delivered_at': '2024-05-01 12:00', 'distance_km': 2.5}, {'picked_up_at': '2024-05-01 12:05', 'delivered_at': '2024-05-01 12:30', 'distance_km': 1.0}])

Expected Output: 28.0

Explanation: The first two deliveries are payable by 12:00. Their payouts are 11.00 and 17.00, for a total of 28.00.

Input: ('2024-05-01 18:45', [{'picked_up_at': '2024-05-01 18:00', 'delivered_at': '2024-05-01 18:45', 'distance_km': 4.0}])

Expected Output: 15.2

Explanation: Equality counts. Payout = 3.00 + 3.20 + 9.00 = 15.20.

Input: ('2024-05-01 09:00', [])

Expected Output: 0.0

Explanation: No deliveries means nothing is owed.

Input: ('2024-05-01 09:00', [{'picked_up_at': '2024-05-01 10:00', 'delivered_at': '2024-05-01 10:10', 'distance_km': 1.0}, {'picked_up_at': '2024-05-01 11:00', 'delivered_at': '2024-05-01 11:30', 'distance_km': 3.0}])

Expected Output: 0.0

Explanation: The query time is before all delivered_at values, so no delivery is payable yet.

Hints

  1. A delivery contributes to the answer only if its delivered_at is less than or equal to the query timestamp.
  2. Compute the payout for each eligible delivery independently, then add them up.

Part 3: Efficiently Answer Many Driver Payout Queries

You need to support a very large number of completed deliveries and many payout queries at arbitrary timestamps. A delivery becomes payable at delivered_at. For each query timestamp, return the total amount owed to all drivers for deliveries with delivered_at <= query timestamp. Each delivery payout is: - Fixed completion bonus: $3.00 - Distance payout: $0.80 * distance_km - Time payout: $0.20 per minute from picked_up_at to delivered_at Implement a solution that is more efficient than scanning every delivery for every query.

Constraints

  • 0 <= len(deliveries) <= 200000
  • 0 <= len(query_timestamps) <= 200000
  • All timestamps use the format 'YYYY-MM-DD HH:MM' and are in the same timezone.
  • For every delivery, picked_up_at <= delivered_at.
  • All timestamps are exact to the minute.

Examples

Input: ([{'picked_up_at': '2024-05-01 10:00', 'delivered_at': '2024-05-01 10:20', 'distance_km': 5.0}, {'picked_up_at': '2024-05-01 11:00', 'delivered_at': '2024-05-01 11:15', 'distance_km': 1.5}, {'picked_up_at': '2024-05-01 12:00', 'delivered_at': '2024-05-01 12:40', 'distance_km': 3.0}], ['2024-05-01 11:00', '2024-05-01 12:40', '2024-05-01 09:59', '2024-05-01 11:15'])

Expected Output: [11.0, 31.6, 0.0, 18.2]

Explanation: The answers must follow the query order, not sorted order.

Input: ([{'picked_up_at': '2024-05-01 18:00', 'delivered_at': '2024-05-01 18:30', 'distance_km': 2.0}, {'picked_up_at': '2024-05-01 18:10', 'delivered_at': '2024-05-01 18:30', 'distance_km': 1.0}], ['2024-05-01 18:29', '2024-05-01 18:30', '2024-05-01 18:31'])

Expected Output: [0.0, 18.4, 18.4]

Explanation: Multiple deliveries can share the same delivered_at time. They all become payable at that timestamp.

Input: ([], ['2024-05-01 10:00', '2024-05-01 12:00'])

Expected Output: [0.0, 0.0]

Explanation: With no deliveries, every query returns 0.00.

Input: ([{'picked_up_at': '2024-05-01 10:00', 'delivered_at': '2024-05-01 10:10', 'distance_km': 1.0}], [])

Expected Output: []

Explanation: No queries means no results.

Hints

  1. Sort deliveries by delivered_at, then build a prefix-sum array of cumulative payouts.
  2. For each query timestamp, use binary search to find how many deliveries are payable by that time.
Last updated: Apr 19, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement a Searchable Logger Pipeline - Rippling (hard)
  • Implement an In-Memory File System - Rippling
  • Compare Complete and Partial Poker Hands - Rippling (medium)
  • Implement Courier Delivery Cost Tracking - Rippling (medium)
  • Implement Article Vote Tracking - Rippling (medium)