Car Rental Assignment
Asked at Google· Screen
Reported by the problem's creator, not verified
Cars are numbered 0, 1, 2, ... in the order they are first used. Each reservation is [id, pickup, return]: the assigned car is out for the half-open interval [pickup, return).
assign_cars(rentals) returns one car number per reservation: result[i] is the car assigned to rentals[i], in the original order of rentals.
Examples
Example 1
Input: rentals =
[[1,1,4],[2,2,5],[3,4,6]]Output:
[0,1,0]Explanation: Rental 1 takes car 0. Rental 2 starts at 2 while car 0 is out, so it opens car 1. Rental 3 starts at 4, the moment rental 1 returns, so it reuses car 0. Two cars serve all three.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.