Meeting Rooms II
MediumThis is an extra practice problem. It doesn't have walkthrough slides. You can solve it with the pattern template you already know. Open the hints if you get stuck.
Question
You're given intervals, a list of conference room bookings. Each entry is [start, end]. Two bookings that overlap need separate rooms. Return the fewest rooms you'd need so that every meeting has a room for its whole booked time.
Input: intervals = [[0, 30], [5, 10], [15, 20]]
Output: 2
[5, 10] and [15, 20] both fall inside [0, 30]. They don't overlap each other. That means one room can hold both of them. A second room holds [0, 30].
Input: intervals = [[7, 10], [2, 4]]
Output: 1
These bookings don't overlap. One room is enough for both.
Input: intervals = [[1, 4], [4, 5]]
Output: 1
The first booking ends exactly when the second one begins. The room is free again by then. That means you only need one room.
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
Remember to understand the problem and plan your approach before you start coding.