100 XP

93. Meeting rooms needed

Advanced intervals sorting

Each meeting runs from its start time to its end time, written [start, end]. A room holds one meeting at a time, and a meeting that ends at 10 frees its room for a meeting that starts at 10.

Write a function rooms_needed(meetings) that takes the day's meetings, in any order, and returns the fewest rooms that can hold them all. That is the largest number of meetings going on at the same moment.

  • Meetings that touch, one ending as the next starts, don't overlap: [1, 5] and [5, 8] fit in one room.
  • No meetings need no rooms: 0.

Example 1

Inputmeetings = [[9, 10], [9, 12], [11, 13]]
Output2
ExplanationTwo meetings at 9; at 11 the first is over.

Example 2

Inputmeetings = [[1, 5], [5, 8]]
Output1
ExplanationBack to back: the room is free at 5.

Example 3

Inputmeetings = []
Output0
ExplanationNothing to hold.

Constraints

  • meetings has 0 to 200 meetings, each [start, end] with whole numbers from 0 to 10,000 and start < end.

Submit also runs 8 more tests you can't see.

Code
def rooms_needed(meetings):
    """Find the fewest rooms that hold all the meetings.

    meetings: list of [start, end] pairs, in any order
    Returns: int, the most meetings going on at once
    """
    # Write your code here
    pass