Trains the technique from
LeetCode 253Meeting Rooms IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
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.
Example 1
Each vehicle unplugs exactly as the next one arrives, so one bay is handed down the whole chain.
Example 2
At minute 4 all three vehicles are plugged in at once, so the depot cannot get by with fewer than 3 bays.
Example 3
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.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def peak_bay_demand(sessions: list[list[int]]) -> int:public int peakBayDemand(int[][] sessions)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.