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

DSA
Medium
Microsoft Corporation
64.4K views

Direct Answer

This problem tests your ability to apply greedy algorithms and priority queues to resource allocation scenarios. It requires sorting intervals and tracking overlaps efficiently.

Why Interviewers Ask This

Meeting room scheduling is a real-world application of interval management. Interviewers ask this to see if you can optimize resources using efficient data structures. It evaluates your skill in transforming a temporal problem into a computational one using heaps.

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, checking if the earliest ending meeting has finished before the current one starts. If so, remove it from the heap and reuse the room; otherwise, allocate a new room. The size of the heap at any point represents the number of rooms needed.

Key Points to Cover

  • Sorting by start time
  • Using a min-heap for end times
  • Greedy assignment logic
  • Heap size as room count

Sample Answer

First, sort all meetings based on their start times. Then, initialize a min-heap to keep track of meeting end times. For each meeting, check if its start time is greater than or equal to the smallest end time in the heap…

Common Mistakes to Avoid

  • Sorting by end time instead of start
  • Failing to update the heap correctly
  • Not considering overlapping intervals properly

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 127 DSA questionsBrowse all 50 Microsoft Corporation questions