Count meeting rooms
Return the fewest rooms for positive-length half-open meeting intervals [start,end). A meeting may start when another ends.
import heapq
active_ends = [3, 7]
next_start = 3
while active_ends and active_ends[0] <= next_start:
heapq.heappop(active_ends)
print(active_ends)Reason about the state
Sort meetings by start and keep active end times in a min-heap. Remove all ended meetings before adding the next; record the largest active count. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the fewest rooms for positive-length half-open meeting intervals [start,end). A meeting may start when another ends.
The explanation opens here once every check passes.