Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the intervals by their start time.
DSA Typescript
intervals.sort((a, b) => [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect properties like 'start - end' which is invalid.
Using just '-' without properties.
Using '.start - b.start' which is syntax error.
✗ Incorrect
We sort intervals by their start time using a.start - b.start to order them from earliest to latest.
2fill in blank
mediumComplete the code to check if the current meeting starts after the earliest ending meeting.
DSA Typescript
if (intervals[i].start >= [1]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using array indexing like heap[0] when min heap is a class.
Using minHeap[0] which may not be valid for heap structure.
✗ Incorrect
We use minHeap.peek() to get the earliest ending meeting's end time without removing it.
3fill in blank
hardFix the error in the code to add the current meeting's end time to the min heap.
DSA Typescript
minHeap.[1](intervals[i].end);Attempts:
3 left
💡 Hint
Common Mistakes
Using push() which is for arrays, not heaps.
Using add() or enqueue() which may not exist in this heap class.
✗ Incorrect
The min heap uses insert() method to add new elements while maintaining heap property.
4fill in blank
hardFill both blanks to remove the earliest ending meeting and add the current meeting's end time.
DSA Typescript
if (intervals[i].start >= minHeap.peek()) { minHeap.[1](); } minHeap.[2](intervals[i].end);
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() which may not be defined for min heap.
Using remove() which is ambiguous.
Using insert() before removing the earliest meeting.
✗ Incorrect
extractMin() removes the smallest element, and insert() adds the current meeting's end time.
5fill in blank
hardFill the blank to return the minimum number of meeting rooms needed.
DSA Typescript
return minHeap.[1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using length which is for arrays, not heap.
Using count or capacity which may not exist.
✗ Incorrect
The size property of the min heap gives the number of rooms currently used.
