Manage Forum Mall Parking
MediumP3Coding
A mall has k parking slots. Vehicle i arrives at time arrival[i] and leaves at time departure[i], and occupies a slot during [arrival[i], departure[i]): a slot freed at time t can be taken by a vehicle arriving at time t. Return true if every vehicle can be parked, that is, at no moment more than k vehicles are present; otherwise return false.
(The original prints "Possible" or "Not Possible"; here you return a boolean.)
Example 1
- Input
- k = 2, arrival = [1,2,3], departure = [4,5,6]
- Output
- false
- Why
- Between times 3 and 4 all three vehicles are parked.
Example 2
- Input
- k = 1, arrival = [1,3], departure = [3,5]
- Output
- true
- Why
- The second vehicle arrives exactly when the first leaves.
Constraints
- 1 <= k <= 10^5
- 1 <= n <= 10^5
- 0 <= arrival[i] < departure[i] <= 10^9, with arrival and departure in matching order by vehicle (not necessarily sorted)
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.