Challenge - 5 Problems
Meeting Rooms Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateMinimum Meeting Rooms Required - Output Check
What is the output of the following Go code that calculates the minimum number of meeting rooms required for given intervals?
DSA Go
package main import ( "fmt" "sort" ) type Interval struct { start int end int } func minMeetingRooms(intervals []Interval) int { if len(intervals) == 0 { return 0 } starts := make([]int, len(intervals)) ends := make([]int, len(intervals)) for i, interval := range intervals { starts[i] = interval.start ends[i] = interval.end } sort.Ints(starts) sort.Ints(ends) rooms := 0 endIndex := 0 for i := 0; i < len(starts); i++ { if starts[i] < ends[endIndex] { rooms++ } else { endIndex++ } } return rooms } func main() { intervals := []Interval{{0, 30}, {5, 10}, {15, 20}} fmt.Println(minMeetingRooms(intervals)) }
Attempts:
2 left
💡 Hint
Think about how many meetings overlap at the same time.
✗ Incorrect
The code sorts start and end times separately and uses two pointers to track ongoing meetings. It increments room count when a meeting starts before the earliest ending meeting ends. For the given intervals, maximum overlap is 2.
❓ Predict Output
intermediateMinimum Rooms for Overlapping Meetings
What will be printed by this Go program that finds the minimum number of meeting rooms needed?
DSA Go
package main import ( "fmt" "sort" ) type Interval struct { start int end int } func minMeetingRooms(intervals []Interval) int { starts := []int{} ends := []int{} for _, interval := range intervals { starts = append(starts, interval.start) ends = append(ends, interval.end) } sort.Ints(starts) sort.Ints(ends) rooms := 0 endIndex := 0 for i := 0; i < len(starts); i++ { if starts[i] < ends[endIndex] { rooms++ } else { endIndex++ } } return rooms } func main() { intervals := []Interval{{1, 5}, {2, 6}, {8, 9}, {8, 9}} fmt.Println(minMeetingRooms(intervals)) }
Attempts:
2 left
💡 Hint
Count how many meetings overlap at the same time.
✗ Incorrect
The maximum number of overlapping meetings is 2: meetings [1,5] and [2,6] overlap, and meetings [8,9] and [8,9] overlap but only need 2 rooms total.
🧠 Conceptual
advancedWhy Sorting Start and End Times Separately Works
Why does sorting the start times and end times separately help in finding the minimum number of meeting rooms required?
Attempts:
2 left
💡 Hint
Think about how to know when a meeting room becomes free.
✗ Incorrect
Sorting start and end times separately lets us compare the earliest starting meeting with the earliest ending meeting to know if a room is free or a new room is needed.
🔧 Debug
advancedIdentify the Bug in Meeting Rooms Code
What error will this Go code produce when run, and why?
DSA Go
package main import ( "fmt" "sort" ) type Interval struct { start int end int } func minMeetingRooms(intervals []Interval) int { starts := []int{} ends := []int{} for _, interval := range intervals { starts = append(starts, interval.start) ends = append(ends, interval.end) } sort.Ints(starts) sort.Ints(ends) rooms := 0 endIndex := 0 for i := 0; i <= len(starts); i++ { if starts[i] < ends[endIndex] { rooms++ } else { endIndex++ } } return rooms } func main() { intervals := []Interval{{1, 10}, {2, 7}, {3, 19}} fmt.Println(minMeetingRooms(intervals)) }
Attempts:
2 left
💡 Hint
Check the loop condition carefully.
✗ Incorrect
The loop uses i <= len(starts) which causes i to go out of bounds since valid indices are 0 to len(starts)-1.
🚀 Application
expertCalculate Minimum Meeting Rooms for Complex Schedule
Given the following intervals, what is the minimum number of meeting rooms required?
DSA Go
intervals := []Interval{{0, 10}, {5, 15}, {10, 20}, {15, 25}, {20, 30}, {25, 35}}Attempts:
2 left
💡 Hint
Visualize the overlapping intervals on a timeline.
✗ Incorrect
The maximum overlap is 2, occurring for example between times 5-10 ([0,10],[5,15]) and 10-15 ([5,15],[10,20]), requiring 2 rooms.
