Meeting Rooms Ii

interview_workbook/leetcode/intervals /app/src/interview_workbook/leetcode/intervals/meeting_rooms_ii.py
View Source

Algorithm Notes

Summary: Meeting Rooms Ii — notes not yet curated.
Time: Estimate via loops/recurrences; common classes: O(1), O(log n), O(n), O(n log n), O(n^2)
Space: Count auxiliary structures and recursion depth.
Tip: See the Big-O Guide for how to derive bounds and compare trade-offs.

Big-O Guide

Source

"""
Meeting Rooms Ii

TODO: Add problem description
"""

from src.interview_workbook.leetcode._registry import register_problem
from src.interview_workbook.leetcode._types import Category, Difficulty


class Solution:
    def solve(self, *args):
        """
        Meeting Rooms II: Minimum meeting rooms required.
        Args:
            intervals (List[List[int]])
        Returns:
            int
        """
        (intervals,) = args
        if not intervals:
            return 0
        starts = sorted([i[0] for i in intervals])
        ends = sorted([i[1] for i in intervals])
        s = e = 0
        rooms = available = 0
        while s < len(intervals):
            if starts[s] < ends[e]:
                if available == 0:
                    rooms += 1
                else:
                    available -= 1
                s += 1
            else:
                available += 1
                e += 1
        return rooms


def demo():
    """TODO: Implement demo function."""
    pass


register_problem(
    id=253,
    slug="meeting_rooms_ii",
    title="Meeting Rooms II",
    category=Category.INTERVALS,
    difficulty=Difficulty.MEDIUM,
    tags=["array", "two_pointers", "greedy", "sorting", "heap"],
    url="https://leetcode.com/problems/meeting-rooms-ii/",
    notes="",
)