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 TypeScript code that calculates the minimum number of meeting rooms required?
DSA Typescript
function minMeetingRooms(intervals: number[][]): number {
if (intervals.length === 0) return 0;
const starts = intervals.map(i => i[0]).sort((a, b) => a - b);
const ends = intervals.map(i => i[1]).sort((a, b) => a - b);
let rooms = 0, endIndex = 0;
for (let i = 0; i < starts.length; i++) {
if (starts[i] < ends[endIndex]) {
rooms++;
} else {
endIndex++;
}
}
return rooms;
}
console.log(minMeetingRooms([[0, 30], [5, 10], [15, 20]]));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 input, two meetings overlap, so minimum rooms needed is 2.
❓ Predict Output
intermediateMinimum Meeting Rooms - Different Input
What is the output of this TypeScript function for the given meeting intervals?
DSA Typescript
function minMeetingRooms(intervals: number[][]): number {
if (intervals.length === 0) return 0;
const starts = intervals.map(i => i[0]).sort((a, b) => a - b);
const ends = intervals.map(i => i[1]).sort((a, b) => a - b);
let rooms = 0, endIndex = 0;
for (let i = 0; i < starts.length; i++) {
if (starts[i] < ends[endIndex]) {
rooms++;
} else {
endIndex++;
}
}
return rooms;
}
console.log(minMeetingRooms([[7, 10], [2, 4]]));Attempts:
2 left
💡 Hint
Check if any meetings overlap.
✗ Incorrect
The meetings [7,10] and [2,4] do not overlap, so only one room is needed.
🧠 Conceptual
advancedUnderstanding the Two Pointer Technique in Meeting Rooms
In the minimum meeting rooms problem, why do we sort start and end times separately and use two pointers to traverse them?
Attempts:
2 left
💡 Hint
Think about how to detect overlapping intervals efficiently.
✗ Incorrect
Sorting starts and ends separately allows us to move through meetings in chronological order, counting how many meetings overlap at any time by comparing start times with earliest end times.
🔧 Debug
advancedIdentify the Bug in Meeting Rooms Code
What error or wrong output will this TypeScript code produce when calculating minimum meeting rooms?
DSA Typescript
function minMeetingRooms(intervals: number[][]): number {
if (intervals.length === 0) return 0;
const starts = intervals.map(i => i[0]).sort();
const ends = intervals.map(i => i[1]).sort();
let rooms = 0, endIndex = 0;
for (let i = 0; i < starts.length; i++) {
if (starts[i] < ends[endIndex]) {
rooms++;
} else {
endIndex++;
}
}
return rooms;
}
console.log(minMeetingRooms([[1, 3], [2, 4], [10, 12]]));Attempts:
2 left
💡 Hint
Check how the sort method is used on numbers.
✗ Incorrect
The code uses sort() without a compare function, so it sorts numbers as strings, causing incorrect order and wrong room count.
🚀 Application
expertCalculate Minimum Meeting Rooms for Complex Schedule
Given the following meeting intervals, what is the minimum number of meeting rooms required?
DSA Typescript
function minMeetingRooms(intervals: number[][]): number {
if (intervals.length === 0) return 0;
const starts = intervals.map(i => i[0]).sort((a, b) => a - b);
const ends = intervals.map(i => i[1]).sort((a, b) => a - b);
let rooms = 0, endIndex = 0;
for (let i = 0; i < starts.length; i++) {
if (starts[i] < ends[endIndex]) {
rooms++;
} else {
endIndex++;
}
}
return rooms;
}
console.log(minMeetingRooms([[1, 5], [2, 6], [4, 8], [9, 10], [9, 12], [11, 15]]));Attempts:
2 left
💡 Hint
Count maximum overlaps carefully.
✗ Incorrect
The maximum number of overlapping meetings is 3 during intervals [4,5] and [9,10].
