Meeting Rooms II
Real-world version: Peak Charging Bay DemandThe statement here is our own: the same inputs, outputs and technique.
A depot is sizing a bank of identical charging bays before opening day. You are given sessions, where sessions[i] = [arrive_i, leave_i] is the minute a vehicle plugs in and the minute it unplugs.
A bay serves one vehicle at a time. A vehicle holds its bay over the half-open span from arrive_i up to leave_i, so a vehicle unplugging at minute t hands the bay straight to a vehicle arriving at minute t. Two sessions that merely touch at an endpoint therefore never contend for a bay.
Return the smallest bay count that lets the depot honour every session in sessions.
Examples
Example 1
- Input
- sessions = [[4, 9], [9, 14], [14, 20]]
- Output
- 1
Each vehicle unplugs exactly as the next one arrives, so one bay is handed down the whole chain.
Example 2
- Input
- sessions = [[0, 12], [3, 6], [4, 8]]
- Output
- 3
At minute 4 all three vehicles are plugged in at once, so the depot cannot get by with fewer than 3 bays.
Example 3
- Input
- sessions = [[10, 20], [30, 40], [15, 35]]
- Output
- 2
The long session spanning minutes 15 to 35 doubles up first with the 10-to-20 session and later with the 30-to-40 one, but the first and second sessions never coincide, so 2 bays suffice.
Constraints
- 1 <= sessions.length <= 10^4
- sessions[i].length == 2
- 0 <= arrive_i < leave_i <= 10^6
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def peak_bay_demand(sessions: list[list[int]]) -> int:public int peakBayDemand(int[][] sessions)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Assign CookiesReal-world version: Scratch Space HandoutEasy
- Earliest Finish Time for Land and Water Rides IReal-world version: Forge and Kiln BookingEasy
- Longest Subsequence With Limited SumReal-world version: Parcels Within Each AllowanceEasy
- Make Array Zero by Subtracting Equal AmountsReal-world version: Rounds Needed to Clear Every ReadingEasy