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 Rust code that calculates the minimum number of meeting rooms required for given intervals?
DSA Rust
fn min_meeting_rooms(intervals: Vec<(i32, i32)>) -> i32 {
let mut starts: Vec<i32> = intervals.iter().map(|x| x.0).collect();
let mut ends: Vec<i32> = intervals.iter().map(|x| x.1).collect();
starts.sort_unstable();
ends.sort_unstable();
let mut rooms = 0;
let mut end_ptr = 0;
for start in starts {
if start < ends[end_ptr] {
rooms += 1;
} else {
end_ptr += 1;
}
}
rooms
}
fn main() {
let intervals = vec![(0, 30), (5, 10), (15, 20)];
println!("{}", min_meeting_rooms(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 overlaps. It increments rooms when a meeting starts before the earliest ending meeting ends. For the given intervals, the maximum overlap is 2.
🧠 Conceptual
intermediateUnderstanding the Two Pointer Technique in Meeting Rooms
In the Meeting Rooms problem, why do we sort the start and end times separately and use two pointers to traverse them?
Attempts:
2 left
💡 Hint
Think about how sorting helps in comparing start and end times in order.
✗ Incorrect
Sorting start and end times separately allows us to compare the earliest starting meeting with the earliest ending meeting to detect overlaps efficiently.
🔧 Debug
advancedIdentify the Bug in Meeting Rooms Code
What error will the following Rust code produce when run, and why?
DSA Rust
fn min_meeting_rooms(intervals: Vec<(i32, i32)>) -> i32 {
let mut starts: Vec<i32> = intervals.iter().map(|x| x.0).collect();
let mut ends: Vec<i32> = intervals.iter().map(|x| x.1).collect();
starts.sort();
ends.sort();
let mut rooms = 0;
let mut end_ptr = 0;
for start in starts {
if start <= ends[end_ptr] {
rooms += 1;
} else {
end_ptr += 1;
}
}
rooms
}
fn main() {
let intervals = vec![(0, 30), (5, 10), (10, 20)];
println!("{}", min_meeting_rooms(intervals));
}Attempts:
2 left
💡 Hint
Check the comparison operator in the if condition and how end_ptr is incremented.
✗ Incorrect
Using <= causes rooms to increment even when a meeting starts exactly when another ends, leading to overcounting rooms. The output is 3 instead of the correct 2.
📝 Syntax
advancedIdentify the Syntax Error in Rust Meeting Rooms Code
Which option contains a syntax error in this Rust code snippet for minimum meeting rooms?
DSA Rust
fn min_meeting_rooms(intervals: Vec<(i32, i32)>) -> i32 {
let mut starts = intervals.iter().map(|x| x.0).collect::<Vec<i32>>();
let mut ends = intervals.iter().map(|x| x.1).collect::<Vec<i32>>();
starts.sort_unstable();
ends.sort_unstable();
let mut rooms = 0;
let mut end_ptr = 0;
for start in starts {
if start < ends[end_ptr] {
rooms += 1;
} else {
end_ptr += 1;
}
}
rooms
}Attempts:
2 left
💡 Hint
Look carefully at each line's ending punctuation.
✗ Incorrect
The line 'starts.sort_unstable()' is missing a semicolon, causing a syntax error.
🚀 Application
expertCalculate Minimum Meeting Rooms for Complex Intervals
Given the intervals [(1,4), (2,5), (7,9), (3,6), (10,11), (8,10)], what is the minimum number of meeting rooms required?
Attempts:
2 left
💡 Hint
Visualize overlapping intervals on a timeline and count maximum overlaps.
✗ Incorrect
The maximum number of overlapping meetings is 3, occurring between intervals (1,4), (2,5), and (3,6).
