What is the minimum number of meeting rooms required for overlapping meetings?

DSA
Medium
Microsoft
130.4K views

Solve the interval scheduling problem to determine the maximum number of simultaneous meetings occurring at any point in time.

Why Interviewers Ask This

This problem tests your ability to work with intervals and prioritize events using heaps or sorting. It simulates real-world resource allocation scenarios where efficiency is key. Interviewers evaluate your skill in optimizing algorithms to handle time-based constraints and your ability to reduce complex scheduling problems to simpler computational steps.

How to Answer This Question

Sort the meetings by their start times. Use a min-heap to track the end times of ongoing meetings. Iterate through the sorted meetings; if the current meeting starts after the earliest ending meeting, reuse that room. Otherwise, allocate a new room. The size of the heap at the end represents the minimum rooms needed. Alternatively, use a sweep-line algorithm with start and end events.

Key Points to Cover

  • Sorting by start time
  • Using a min-heap for end times
  • Reusing rooms when possible
  • Heap size as the answer

Sample Answer

First, I sort the meetings by start time. Then, I use a min-heap to store the end times of meetings currently occupying rooms. For each meeting, I check if its start time is greater than the smallest end time in the heap. If so, I remove the oldest meeting and add the current one, effectively reusing the room. If not, I add the current meeting's end time to the heap, indicating a new room is needed. The final heap size gives the minimum rooms required.

Common Mistakes to Avoid

  • Sorting by end time instead of start time
  • Incorrectly managing heap operations
  • Overlooking edge cases with identical start/end times

Practice This Question with AI

Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.

Start Practicing

Related Interview Questions

Browse all 35 DSA questionsBrowse all 84 Microsoft questions