Skip to Content

Meeting Rooms II - Interval scheduling

Home | Coding Interviews | Stacks and Queues | Meeting Rooms II - Interval scheduling

Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

class Solution:
  def minMeetingRooms(self, intervals: List[Interval]) -> bool:
  intervals.sort(key=lambda i: i.start)
      for i in range(1, len(intervals)):
          i1 = intervals[i - 1]
          i2 = intervals[i]
  
          if i1.end > i2.start:
              return False
      return True

#gigabrain solution
class Solution:
    def minMeetingRooms(self, intervals: List[List[int]]) -> int:
        delta = [0] * 1000010
        for start, end in intervals:
            delta[start] += 1
            delta[end] -= 1
        return max(accumulate(delta))

#cute line trace solution
class Solution2(object):
  def minMeetingRooms(self, intervals):
    meetings = []
    for i in intervals:
      meetings.append((i.start, 1))
      meetings.append((i.end, 0))
    meetings.sort()
    ans = 0
    count = 0
    for meeting in meetings:
      if meeting[1] == 1:
        count += 1
      else:
        count -= 1
      ans = max(ans, count)
    return ans

Posted by Jamie Meyer 7 months ago

Related Problems

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Implement the MinStack class:

MinStack() initializes the stack object.

void push(int val) pushes the element val onto the stack.

void pop() removes the element on the top of the stack.

int top() gets the top element of the stack.

int getMin() retrieves the minimum element in the stack.

You must implement a solution with O(1) time complexity for each function.

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.

Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.