FastPrepTrip Booking with the Earliest Free Driver
Problems/Trip Booking with the Earliest Free Driver

Trip Booking with the Earliest Free Driver

Rippling logoRippling● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Rippling SDE-1 report from February 2026 covers a booking class for drivers who are paid by the hour, asked in the first onsite round, a DSA round. The class signs up drivers, gives each trip to a free driver, prices every trip and keeps a running total. A follow-up asks how many drivers the trips need at one point in time.

The report does not define which free driver is first in line, gives no input format, limits or tie rules, and does not say what happens when no driver is free. Here, the calls come as one list of names and numbers, and times are whole hours. A trip goes to the free driver whose last trip ended earliest, ties go to the smaller id, and a driver who has never driven counts as free since hour 0. A driver is free again at the exact hour their last trip ends, so a new trip may start at that hour. A trip no driver can take returns -1 and is not booked. Trip start hours never go down. The fewest drivers needed at an hour counts every trip asked for so far, booked or not, that has started by that hour and not yet ended, so a trip that ends at that exact hour is not counted. The limits and examples are our own.

Our version is about 75% the same as the reported question.

A travel company books trips for its drivers. Each driver is paid an hourly rate. Times are whole hours. Build a booking system that starts with no drivers and no trips, and supports four calls:

  • addDriver(hourlyRate): add a driver. Drivers get ids 0, 1, 2, ... in the order they are added. Return the new driver's id.
  • bookTrip(start, end): a customer asks for a trip from hour start to hour end. A driver is free for it if every trip they already drive ends at or before start. Give the trip to the free driver who has been free the longest, that is, whose last trip ended earliest. A driver who has never driven counts as free since hour 0. If two free drivers have been free since the same hour, pick the smaller id. Return the trip's cost, which is the driver's hourlyRate × (end - start). If no driver is free, the trip is not booked: return -1.
  • getTotalCost(): return the total cost of all trips booked so far.
  • getMinDrivers(time): return the fewest drivers needed to drive every trip asked for so far that is running at hour time. Count every bookTrip request so far, booked or not, with start <= time < end. A trip that ends at hour time is not running then.

You get the calls in order: operations[i] is the call's name and args[i] holds its numbers. Return an array with one value per call, in order.

Function

runTripBookings(operations: String[], args: int[][]) → long[]

Examples

Example 1

operations = ["addDriver","addDriver","bookTrip","bookTrip","bookTrip","getTotalCost","getMinDrivers"]args = [[30],[20],[1,4],[2,5],[4,6],[],[4]]return = [0,1,90,60,60,210,2]

Driver 0 costs 30 per hour and driver 1 costs 20. Both are free at hour 1; neither has driven, so the smaller id, driver 0, takes trip [1, 4] for 30 × 3 = 90. At hour 2 only driver 1 is free: 20 × 3 = 60. At hour 4 driver 0 is free again (its trip ended at 4) and costs 30 × 2 = 60. The total is 210. At hour 4 the trips [2, 5] and [4, 6] are running, so 2 drivers are needed.

Example 2

operations = ["addDriver","addDriver","bookTrip","bookTrip","bookTrip","bookTrip","getTotalCost"]args = [[10],[50],[0,2],[0,1],[3,4],[3,5],[]]return = [0,1,20,50,50,20,140]

Driver 0 drives [0, 2] (cost 20) and driver 1 drives [0, 1] (cost 50). At hour 3 both are free. Driver 1 has been free since hour 1 and driver 0 since hour 2, so driver 1 takes [3, 4] (cost 50), even though driver 0 is cheaper. Then driver 0 takes [3, 5] (cost 20). The total is 140.

Example 3

operations = ["addDriver","bookTrip","bookTrip","getMinDrivers","getMinDrivers","getTotalCost"]args = [[7],[5,9],[6,8],[6],[9],[]]return = [0,28,-1,2,0,28]

Driver 0 takes [5, 9] for 7 × 4 = 28. At hour 6 it is still busy, so [6, 8] cannot be booked: -1. Two trips were asked for at hour 6, so 2 drivers would be needed then. At hour 9 the first trip has just ended: 0. The total stays 28.

Constraints

  • 1 <= operations.length <= 2000 and args.length == operations.length
  • Each operations[i] is "addDriver", "bookTrip", "getTotalCost" or "getMinDrivers", and args[i] holds [hourlyRate], [start, end], [] or [time] to match.
  • Every number in args is between 0 and 10^6.
  • 1 <= hourlyRate <= 10^4 and start < end
  • The start hours of the bookTrip calls never go down from one call to the next.

More Rippling Onsite Interview questions

  • Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Delivery Cost TrackerPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Maximum Currency Conversion Along a Simple PathPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Top K Frequent WordsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Future-Effective Employee SalaryONSITE INTERVIEW · Seen Aug 2026
  • Filter and Sort Scheduled TasksONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
  • Delayed Job SchedulerWalmart Labs · ONSITE INTERVIEW
  • Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
  • Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Implement a Min-Priority QueueAmazon · ONSITE INTERVIEW
  • Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Key-Value Store with Hit CounterDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Priority Job Scheduler with CooldownsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Reusable Number AllocatorDropbox · ONSITE INTERVIEWDropbox interview questions

Interview reports that mention this question

  • Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
  • Rippling SWE Interviews, No Level: 156 Experiences (Part 1 of 6)

Rippling interview experiences

  • Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
  • Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
  • Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
  • Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)
All Rippling interview questionsSee Rippling hiring insights
Saved
class Solution {
    public long[] runTripBookings(String[] operations, int[][] args) {
        // Write your code here.
    }
}
Checking account…