Bird
Raised Fist0
DSA Goprogramming~20 mins

Meeting Rooms Problem Minimum Rooms Required in DSA Go - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Meeting Rooms Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Minimum 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))
}
A1
B3
C2
D0
Attempts:
2 left
💡 Hint
Think about how many meetings overlap at the same time.
❓ Predict Output
intermediate
2:00remaining
Minimum 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))
}
A2
B3
C4
D1
Attempts:
2 left
💡 Hint
Count how many meetings overlap at the same time.
🧠 Conceptual
advanced
2:00remaining
Why 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?
AIt allows us to track when meetings start and end independently to count overlaps efficiently.
BIt merges all intervals into one big interval to simplify counting.
CIt sorts meetings by duration to allocate rooms based on length.
DIt groups meetings by their start times to assign rooms in batches.
Attempts:
2 left
💡 Hint
Think about how to know when a meeting room becomes free.
🔧 Debug
advanced
2:00remaining
Identify 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))
}
Acompilation error due to missing import
Breturns incorrect number of rooms due to wrong comparison operator
Creturns 0 because intervals are empty
Druntime error: index out of range because loop goes beyond slice length
Attempts:
2 left
💡 Hint
Check the loop condition carefully.
🚀 Application
expert
3:00remaining
Calculate 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}}
A3
B2
C4
D5
Attempts:
2 left
💡 Hint
Visualize the overlapping intervals on a timeline.

Practice

(1/5)
1. What does the "Meeting Rooms Problem Minimum Rooms Required" ask you to find given a list of meeting time intervals?
easy
A. The earliest meeting start time
B. The maximum length of a single meeting
C. The minimum number of meeting rooms needed so no meetings overlap
D. The total number of meetings scheduled

Solution

  1. Step 1: Understand the problem goal

    The problem asks for the minimum number of rooms needed so that no two meetings overlap in the same room.
  2. Step 2: Clarify what is being counted

    We count how many meetings happen at the same time to find the minimum rooms required.
  3. Final Answer:

    The minimum number of meeting rooms needed so no meetings overlap -> Option C
  4. Quick Check:

    Minimum rooms = max overlapping meetings [OK]
Hint: Count max overlapping intervals to find rooms needed [OK]
Common Mistakes:
  • Confusing total meetings with rooms needed
  • Ignoring overlapping times
  • Thinking earliest start time is the answer
2. Which Go data structure is best to store meeting intervals for solving the minimum rooms problem?
easy
A. [][]int
B. string
C. map[int]int
D. chan int

Solution

  1. Step 1: Identify suitable data structure for intervals

    Meeting intervals have start and end times, so a slice of slices ([][]int) is ideal to store pairs.
  2. Step 2: Check other options

    map[int]int is less natural for intervals, string can't hold numeric ranges, chan int is for concurrency, not intervals.
  3. Final Answer:

    [][]int -> Option A
  4. Quick Check:

    Intervals stored as pairs in [][]int [OK]
Hint: Use [][]int to hold start and end times pairs [OK]
Common Mistakes:
  • Using map which doesn't keep order
  • Trying to store intervals as strings
  • Using channels which are unrelated here
3. What is the output of the following Go code snippet that calculates minimum meeting rooms needed?
intervals := [][]int{{0, 30}, {5, 10}, {15, 20}}
rooms := minMeetingRooms(intervals)
fmt.Println(rooms)

func minMeetingRooms(intervals [][]int) int {
    starts := []int{}
    ends := []int{}
    for _, interval := range intervals {
        starts = append(starts, interval[0])
        ends = append(ends, interval[1])
    }
    sort.Ints(starts)
    sort.Ints(ends)
    rooms, endIndex := 0, 0
    for i := 0; i < len(starts); i++ {
        if starts[i] < ends[endIndex] {
            rooms++
        } else {
            endIndex++
        }
    }
    return rooms
}
medium
A. 1
B. 2
C. 3
D. 0

Solution

  1. Step 1: Sort start and end times

    Starts = [0,5,15], Ends = [10,20,30]
  2. Step 2: Iterate and count rooms

    At start=0 < end=10, rooms=1; start=5 < end=10, rooms=2; start=15 >= end=10, endIndex++, rooms=2
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Max overlapping meetings = 2 [OK]
Hint: Sort starts and ends, count overlaps to find rooms [OK]
Common Mistakes:
  • Not sorting start and end times
  • Incrementing rooms incorrectly
  • Confusing start and end comparisons
4. Find the bug in this Go function for minimum meeting rooms:
func minMeetingRooms(intervals [][]int) int {
    starts := []int{}
    ends := []int{}
    for _, interval := range intervals {
        starts = append(starts, interval[0])
        ends = append(ends, interval[1])
    }
    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
}
medium
A. Loop condition should be i < len(starts), not <= to avoid out-of-range
B. Should sort starts and ends in descending order
C. Should compare starts[i] > ends[endIndex] instead
D. Should initialize rooms to 1 instead of 0

Solution

  1. Step 1: Check loop boundary

    The loop uses i <= len(starts), which causes index out-of-range error because valid indices are 0 to len(starts)-1.
  2. Step 2: Correct loop condition

    Change to i < len(starts) to safely iterate over all elements.
  3. Final Answer:

    Loop condition should be i < len(starts), not <= to avoid out-of-range -> Option A
  4. Quick Check:

    Index error fixed by proper loop bounds [OK]
Hint: Use < not <= in loops to avoid index errors [OK]
Common Mistakes:
  • Using <= instead of < in for loops
  • Sorting in wrong order
  • Wrong comparison operators
5. Given meeting intervals [[1,4],[2,5],[7,9],[6,8],[9,10]], what is the minimum number of meeting rooms required?
hard
A. 3
B. 1
C. 4
D. 2

Solution

  1. Step 1: Sort start and end times

    Starts = [1,2,6,7,9], Ends = [4,5,8,9,10]
  2. Step 2: Count overlaps to find rooms

    i=0 start=1 < end=4 rooms=1 i=1 start=2 < end=4 rooms=2 i=2 start=6 >= end=4 endIndex=1 rooms=2 i=3 start=7 >= end=5 endIndex=2 rooms=2 i=4 start=9 >= end=8 endIndex=3 rooms=2
  3. Final Answer:

    2 -> Option D
  4. Quick Check:

    Max overlaps = 2 rooms needed [OK]
Hint: Sort starts and ends, increment rooms on overlap [OK]
Common Mistakes:
  • Not sorting intervals before processing
  • Miscounting overlaps at boundaries
  • Assuming one room per meeting always
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard