Leetcode 253 Solution

This article provides solution to leetcode question 253 (meeting-rooms-ii)

https://leetcode.com/problems/meeting-rooms-ii

Solution

class Solution:
    def minMeetingRooms(self, intervals: List[List[int]]) -> int:
        events = []

        for interval in intervals:
            events.append((interval[1], -1))
            events.append((interval[0], 1))

        events.sort()

        ans = 0
        curr_room = 0

        for event in events:
            if event[1] == -1:
                curr_room -= 1
            elif event[1] == 1:
                curr_room += 1
                ans = max(ans, curr_room)

        return ans