Minimum Cars for Rental Requests
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google asked this in April 2026: given rental requests with pickup and return times, find the minimum number of cars needed and assign them deterministically. The catch is that requests are overlapping intervals, and you need to output a specific format showing which car handles which request. This is an interval scheduling problem dressed up as a fleet management question. StealthCoder will catch the pattern if you freeze on the greedy approach.
The problem
You are given rental requests, where each request is represented as [pickupTime, returnTime]. A single car cannot serve overlapping requests. If one request ends exactly when another begins, the same car may serve both. Return one deterministic minimum-car assignment using the following canonical rules: Each returned string must use the format "carId: (p1,r1) (p2,r2)...". The number of returned lines is the minimum number of cars needed. Function Description Complete the function assignMinimumCars in the editor below. assignMinimumCars has the following parameter: Returns Two cars are necessary because the first two requests overlap. Car 0 becomes available at time 3 and can serve the request starting at time 4. Each request starts exactly when the previous one ends, so one car can serve all of them.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The core trick is that this is an interval overlap problem, not a pure scheduling one. Sort requests by pickup time, then greedily assign each request to the car that becomes available earliest (i.e., the car whose return time is earliest and does not overlap). If no car is free, you need a new one. The non-obvious part: requests are overlapping if one starts before another ends, but they do not overlap if one ends exactly when another begins. Track car assignments in order and output them in a deterministic format. The greedy approach minimizes cars because you always reuse the soonest-available car. Most candidates miss the exact formatting requirement or forget to check the boundary case where pickup equals another's return time. StealthCoder sees the interval-overlap pattern and feeds you the greedy assignment strategy live.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Minimum Cars for Rental Requests cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as video stitching. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Cars for Rental Requests FAQ
Is this just sorting plus a min-heap?+
Mostly, yes. Sort by pickup time. Use a min-heap to track when each car becomes free (by return time). For each request, pop the earliest-available car if it's free. If not free, allocate a new car. The heap keeps you from scanning all cars every time.
What does 'deterministic' mean in the output format?+
You must assign cars in a specific order. Likely rule: cars are numbered 0, 1, 2... in the order they are first used. The format is strict: 'carId: (p1,r1) (p2,r2)...' on each line. Don't deviate or the output fails.
Can one car serve requests that end and start at the same time?+
Yes. The problem states: 'If one request ends exactly when another begins, the same car may serve both.' So if request A ends at time 5 and request B starts at time 5, the same car handles both. This is the boundary case many candidates get wrong.
How do I output the assignment in the right order?+
Assign cars as you process requests in sorted order. Car 0 serves the first request it takes. When you allocate a new car, it gets the next ID. Append each request to the car's list. Print each car's line in ID order. No re-sorting the output.
What if two requests have the same pickup time?+
Sort by pickup time, then by return time (ascending) to break ties. This ensures a consistent order and helps the greedy algorithm. Always process the shortest request first so longer ones don't block other cars unnecessarily.