FunctionRacerProblemsRace

One-Bay Car Wash

BeginnerStacks and queuesPython, JavaScript, TypeScript, Java, C++

A car wash has one bay. Car i arrives at minute arrivals[i] and its wash takes durations[i] minutes. Cars are washed one at a time in list order, and a wash starts as soon as its car has arrived and the previous wash is over.

Return the minute at which each wash ends, in list order. arrivals never decreases. Return an empty list when there are no cars.

Example 1

arrivals [0,2,3]
durations [5,1,4]
returns [5,6,10]

Car 0 is washed from 0 to 5. Car 1 waits until 5 and ends at 6, and car 2 waits until 6 and ends at 10.

Example 2

arrivals [1,10]
durations [3,2]
returns [4,12]

The bay is free when each car arrives: 1 to 4, then 10 to 12.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems