Bird
Raised Fist0
DSA C#programming~20 mins

Meeting Rooms Problem Minimum Rooms Required in DSA C# - 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
Output of minimum meeting rooms required calculation
What is the output of the following C# code that calculates the minimum number of meeting rooms required for given meeting intervals?
DSA C#
using System;
using System.Collections.Generic;

public class Solution {
    public int MinMeetingRooms(int[][] intervals) {
        if (intervals.Length == 0) return 0;

        int[] starts = new int[intervals.Length];
        int[] ends = new int[intervals.Length];

        for (int i = 0; i < intervals.Length; i++) {
            starts[i] = intervals[i][0];
            ends[i] = intervals[i][1];
        }

        Array.Sort(starts);
        Array.Sort(ends);

        int rooms = 0, endPtr = 0;

        for (int i = 0; i < starts.Length; i++) {
            if (starts[i] < ends[endPtr]) {
                rooms++;
            } else {
                endPtr++;
            }
        }

        return rooms;
    }
}

public class Program {
    public static void Main() {
        var solution = new Solution();
        int[][] meetings = new int[][] {
            new int[] {0, 30},
            new int[] {5, 10},
            new int[] {15, 20}
        };
        Console.WriteLine(solution.MinMeetingRooms(meetings));
    }
}
A1
B3
C0
D2
Attempts:
2 left
💡 Hint
Think about how many meetings overlap at the same time.
❓ Predict Output
intermediate
2:00remaining
Minimum rooms for non-overlapping meetings
What is the output of this code when all meetings do not overlap?
DSA C#
using System;
using System.Collections.Generic;

public class Solution {
    public int MinMeetingRooms(int[][] intervals) {
        if (intervals.Length == 0) return 0;

        int[] starts = new int[intervals.Length];
        int[] ends = new int[intervals.Length];

        for (int i = 0; i < intervals.Length; i++) {
            starts[i] = intervals[i][0];
            ends[i] = intervals[i][1];
        }

        Array.Sort(starts);
        Array.Sort(ends);

        int rooms = 0, endPtr = 0;

        for (int i = 0; i < starts.Length; i++) {
            if (starts[i] < ends[endPtr]) {
                rooms++;
            } else {
                endPtr++;
            }
        }

        return rooms;
    }
}

public class Program {
    public static void Main() {
        var solution = new Solution();
        int[][] meetings = new int[][] {
            new int[] {1, 2},
            new int[] {3, 4},
            new int[] {5, 6}
        };
        Console.WriteLine(solution.MinMeetingRooms(meetings));
    }
}
A0
B1
C2
D3
Attempts:
2 left
💡 Hint
No meetings overlap, so how many rooms do you need?
🔧 Debug
advanced
2:00remaining
Identify the error in meeting rooms calculation code
What error will this code produce when run, and why?
DSA C#
using System;

public class Solution {
    public int MinMeetingRooms(int[][] intervals) {
        int[] starts = new int[intervals.Length];
        int[] ends = new int[intervals.Length];

        for (int i = 0; i < intervals.Length; i++) {
            starts[i] = intervals[i][0];
            ends[i] = intervals[i][1];
        }

        Array.Sort(starts);
        Array.Sort(ends);

        int rooms = 0, endPtr = 0;

        for (int i = 0; i < starts.Length; i++) {
            if (starts[i] < ends[endPtr]) {
                rooms++;
            } else {
                endPtr++;
            }
        }

        return rooms;
    }
}
AIndexOutOfRangeException because loop goes beyond array length
BNullReferenceException because intervals is null
CInvalidOperationException due to sorting empty array
DNo error, code runs correctly
Attempts:
2 left
💡 Hint
Check the loop condition carefully.
🧠 Conceptual
advanced
1:30remaining
Why sorting start and end times separately helps in meeting rooms problem?
Why do we sort the start times and end times separately when calculating the minimum number of meeting rooms required?
ATo efficiently track when meetings start and end to find overlaps without checking every pair
BTo merge intervals into one big interval
CTo count total meeting duration
DTo find the longest meeting duration
Attempts:
2 left
💡 Hint
Think about how sorting helps in comparing start and end times in order.
❓ Predict Output
expert
2:30remaining
Output of meeting rooms calculation with complex intervals
What is the output of the following code for these meeting intervals?
DSA C#
using System;
using System.Collections.Generic;

public class Solution {
    public int MinMeetingRooms(int[][] intervals) {
        if (intervals.Length == 0) return 0;

        int[] starts = new int[intervals.Length];
        int[] ends = new int[intervals.Length];

        for (int i = 0; i < intervals.Length; i++) {
            starts[i] = intervals[i][0];
            ends[i] = intervals[i][1];
        }

        Array.Sort(starts);
        Array.Sort(ends);

        int rooms = 0, endPtr = 0;

        for (int i = 0; i < starts.Length; i++) {
            if (starts[i] < ends[endPtr]) {
                rooms++;
            } else {
                endPtr++;
            }
        }

        return rooms;
    }
}

public class Program {
    public static void Main() {
        var solution = new Solution();
        int[][] meetings = new int[][] {
            new int[] {1, 10},
            new int[] {2, 7},
            new int[] {3, 19},
            new int[] {8, 12},
            new int[] {10, 20},
            new int[] {11, 30}
        };
        Console.WriteLine(solution.MinMeetingRooms(meetings));
    }
}
A3
B5
C4
D6
Attempts:
2 left
💡 Hint
Count how many meetings overlap at peak time.

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 maximum duration of a single meeting
B. The earliest start time among all meetings
C. The total number of meetings scheduled
D. The minimum number of meeting rooms needed to hold all meetings without overlap

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 rooms, not meetings or durations. The goal is to avoid time conflicts in the same room.
  3. Final Answer:

    The minimum number of meeting rooms needed to hold all meetings without overlap -> Option D
  4. Quick Check:

    Minimum rooms = no overlapping meetings at the same time [OK]
Hint: Count overlaps to find minimum rooms needed [OK]
Common Mistakes:
  • Confusing number of meetings with number of rooms
  • Thinking about meeting durations instead of overlaps
  • Ignoring overlapping intervals
2. Which of the following C# code snippets correctly initializes a list of meeting intervals represented as tuples of start and end times?
easy
A. var meetings = new List<(int, int)> { 9, 10, 11, 12 };
B. var meetings = new List { [9, 10], [11, 12] };
C. var meetings = new List<(int start, int end)> { (9, 10), (11, 12) };
D. var meetings = new List<(int start, int end)> { (start: 9, end: 10), (start: 11) };

Solution

  1. Step 1: Check tuple list initialization syntax

    var meetings = new List<(int start, int end)> { (9, 10), (11, 12) }; correctly uses List of tuples with named elements and proper tuple syntax.
  2. Step 2: Identify errors in other options

    var meetings = new List { [9, 10], [11, 12] }; uses invalid array syntax inside list initialization. var meetings = new List<(int, int)> { 9, 10, 11, 12 }; tries to add ints directly, not tuples. var meetings = new List<(int start, int end)> { (start: 9, end: 10), (start: 11) }; misses end value in second tuple.
  3. Final Answer:

    var meetings = new List<(int start, int end)> { (9, 10), (11, 12) }; -> Option C
  4. Quick Check:

    Correct tuple list syntax = var meetings = new List<(int start, int end)> { (9, 10), (11, 12) }; [OK]
Hint: Use (int, int) tuples with curly braces for intervals [OK]
Common Mistakes:
  • Using square brackets instead of parentheses for tuples
  • Missing tuple elements or names
  • Adding ints instead of tuples
3. Given the following C# code, what is the output?
var intervals = new List<(int start, int end)>{ (0, 30), (5, 10), (15, 20) };
int minRooms = MinMeetingRooms(intervals);
Console.WriteLine(minRooms);

int MinMeetingRooms(List<(int start, int end)> intervals) {
    var starts = intervals.Select(i => i.start).OrderBy(t => t).ToList();
    var ends = intervals.Select(i => i.end).OrderBy(t => t).ToList();
    int rooms = 0, endIndex = 0;
    foreach (var start in starts) {
        if (start < ends[endIndex]) rooms++;
        else endIndex++;
    }
    return rooms;
}
medium
A. 3
B. 2
C. 1
D. 0

Solution

  1. Step 1: Sort start and end times

    Starts = [0, 5, 15], Ends = [10, 20, 30]
  2. Step 2: Iterate starts comparing with ends

    start=0 < 10 -> rooms=1; start=5 < 10 -> rooms=2; start=15 >= 10 -> endIndex=1, no increment rooms; final rooms=2
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Overlapping intervals = 2 rooms needed [OK]
Hint: Sort starts and ends, count overlaps with end pointer [OK]
Common Mistakes:
  • Not sorting start and end times separately
  • Incrementing rooms incorrectly when meetings don't overlap
  • Confusing start and end comparisons
4. The following code attempts to find the minimum number of meeting rooms needed. What is the bug?
int MinRooms(List<(int start, int end)> intervals) {
    intervals.Sort((a, b) => a.start.CompareTo(b.start));
    var heap = new SortedSet<int>();
    foreach (var interval in intervals) {
        if (heap.Count > 0 && interval.start >= heap.Min) {
            heap.Remove(heap.Min);
        }
        heap.Add(interval.end);
    }
    return heap.Count;
}
medium
A. SortedSet does not allow duplicate end times, causing incorrect room count
B. Intervals are not sorted by end time before processing
C. The condition should be interval.start > heap.Min instead of >= to avoid overlap
D. Heap should store start times instead of end times

Solution

  1. Step 1: Understand SortedSet behavior

    SortedSet does not allow duplicates, so multiple meetings ending at same time cause missing removals.
  2. Step 2: Identify impact on room count

    Without duplicates, heap may keep extra end times, inflating room count incorrectly.
  3. Final Answer:

    SortedSet does not allow duplicate end times, causing incorrect room count -> Option A
  4. Quick Check:

    Data structure must allow duplicates for correct room count [OK]
Hint: Use a min-heap that supports duplicates, not SortedSet [OK]
Common Mistakes:
  • Using SortedSet instead of a priority queue or min-heap
  • Confusing start and end time comparisons
  • Incorrect condition for removing from heap
5. You have the following meeting intervals: [(1, 4), (2, 5), (7, 9), (3, 6), (10, 11)]. Using the minimum rooms required approach, what is the minimum number of rooms needed to schedule all meetings without overlap?
hard
A. 3
B. 2
C. 4
D. 1

Solution

  1. Step 1: Sort start and end times

    Starts = [1, 2, 3, 7, 10], Ends = [4, 5, 6, 9, 11]
  2. Step 2: Count overlaps using two pointers

    start=1 < 4 rooms=1; start=2 < 4 rooms=2; start=3 < 4 rooms=3; start=7 >= 4 endIndex=1 no increment rooms; start=10 >= 5 endIndex=2 no increment rooms; final rooms=3
  3. Final Answer:

    3 -> Option A
  4. Quick Check:

    Maximum overlaps = 3 rooms needed [OK]
Hint: Sort starts and ends, increment rooms on overlap [OK]
Common Mistakes:
  • Not sorting intervals before processing
  • Counting rooms incorrectly when meetings end
  • Ignoring overlapping intervals
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