py_room_scheduler

Código comentado línea a línea y paso a paso:

Entregas: py_room_scheduler.py con py_room_scheduler(meetings). Rank 05 · nivel 2.

Qué pide (en palabras normales)

Subject (enunciado original)
Write a function that determines the minimum number of meeting rooms required to schedule a list of meeting time intervals without overlap, and assigns meetings to rooms.

Each meeting is represented as a list of two integers `[start_time, end_time]`.

The function should:
- Sort meetings by start time and assign them to available rooms sequentially.
- Return a dictionary containing:
  - `"total_rooms"`: the integer count of rooms required.
  - `"schedule"`: a list of lists containing the scheduled intervals for each room.
- If the input list is empty, return `{"total_rooms": 0, "schedule": []}`.

Expected file: py_room_scheduler.py
Function signature:
def py_room_scheduler(meetings: list[list[int]]) -> dict[str, Any]:

Examples:
py_room_scheduler([[0, 30], [5, 10], [15, 20]])
=> {"total_rooms": 2, "schedule": [[[0, 30]], [[5, 10], [15, 20]]]}
py_room_scheduler([])
=> {"total_rooms": 0, "schedule": []}

2 piezas

1. Sala libre = su última reunión ya acabó

for room in rooms:
    if room[-1][1] <= start:
        room.append([start, end])
        break

Como voy en orden de inicio, la última reunión de cada sala es la que acaba más tarde. room[-1][1] es ese fin. <=: acabar a las 10 y empezar a las 10 cabe en la misma sala.

2. for ... else

for room in rooms:
    ...
    break
else:
    rooms.append([[start, end]])

El else de un for se ejecuta solo si el bucle terminó sin break: aquí, "ninguna sala estaba libre". Ahorra la bandera placed = False.

Trampas