Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the intervals by their start time.
DSA Rust
intervals.sort_by_key(|interval| interval.[1]);Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by end time instead of start time.
Using incorrect key like length or index.
✗ Incorrect
We sort intervals by their start time to process meetings in chronological order.
2fill in blank
mediumComplete the code to create a min-heap to track meeting end times.
DSA Rust
let mut heap = std::collections::BinaryHeap::new(); heap.push(std::cmp::Reverse(intervals[0].[1]));
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing start time instead of end time.
Pushing length or index instead of time.
✗ Incorrect
We push the end time of the first meeting to track when a room becomes free.
3fill in blank
hardFix the error in the condition to check if the current meeting can reuse a room.
DSA Rust
if intervals[i].start [1] heap.peek().unwrap().0 { heap.pop(); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' which is incorrect for this logic.
Using '==' only which misses cases where start is after end.
✗ Incorrect
We check if the current meeting starts after or exactly when the earliest meeting ends to reuse the room.
4fill in blank
hardFill all three blanks to correctly update the heap with the current meeting's end time and iterate over intervals.
DSA Rust
for [1] in 1..intervals.len() { if intervals[[2]].start >= heap.peek().unwrap().0 { heap.pop(); } heap.push(std::cmp::Reverse(intervals[[3]].end)); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for loop and indexing causing errors.
Using undefined variables.
✗ Incorrect
We use 'i' as the loop variable consistently to access intervals and update the heap.
5fill in blank
hardFill all three blanks to return the minimum number of rooms required after processing all intervals.
DSA Rust
fn min_meeting_rooms(intervals: &mut Vec<Interval>) -> usize {
intervals.sort_by_key(|interval| interval.start);
let mut heap = std::collections::BinaryHeap::new();
heap.push(std::cmp::Reverse(intervals[0].end));
for [1] in 1..intervals.len() {
if intervals[[2]].start >= heap.peek().unwrap().0 {
heap.pop();
}
heap.push(std::cmp::Reverse(intervals[[3]].end));
}
heap.len()
}Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables causing indexing errors.
Returning wrong value instead of heap length.
✗ Incorrect
Using 'i' consistently for loop and indexing ensures correct processing and final count of rooms.
