As reported: Uber SDE-1 online assessment on CodeSignal (June 2025, 3 problems), problem 2: ride batching, also called "Riders Grouping". The aim is to group rides into batches so as to minimize the number of vehicles;
Nup to10000with a 0.5-second limit in C++. Brute force passed the sample tests only.
Each ride is ["ride_id", "pickup_location", "pickup_time"]: ride_id is a positive integer written as a string, pickup_location a string, and pickup_time is "HH:MM" (24-hour clock, all on the same day). Group the rides into batches so that the number of batches (vehicles) is as small as possible:
- a batch holds at most 3 rides;
- rides in a batch have the same pickup_location, and the latest pickup time minus the earliest is at most 10 minutes (inclusive:
09:00,09:05,09:10fit;09:00and09:11do not); - every ride is in exactly one batch.
Return the batches; each batch is a sorted list of integer ride ids, and the batches are ordered by the smallest input index of any ride they contain.
Example
rides = [["1","Downtown","09:00"], ["2","Downtown","09:05"], ["3","Uptown","10:00"],
["4","Downtown","09:12"], ["5","Uptown","10:07"], ["6","Airport","11:00"]]
Output: [[1,2],[3,5],[4],[6]]
Constraints: 1 ≤ N ≤ 10^4; ride ids are distinct and fit in 32 bits.
Clarifications
- Several groupings can use the same minimum number of batches. Build them this way: per location, take the rides in order of pickup time (equal times in input order); the earliest ride not yet batched opens a batch, and the next rides in that order join it while the batch has fewer than 3 rides and they are within 10 minutes of the batch's first ride.
Code runner format: one JSON value per line: rides. Implement batchRides(rides); the harness prints the list of batches.