Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the intervals by their start time.
DSA Java
Arrays.sort(intervals, (a, b) -> a[1]b);Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by end time instead of start time.
Using addition instead of subtraction in comparator.
✗ Incorrect
Sorting intervals by their start time helps to process meetings in chronological order.
2fill in blank
mediumComplete the code to initialize a priority queue that sorts by interval end time.
DSA Java
PriorityQueue<Interval> pq = new PriorityQueue<>((a, b) -> a[1]b);Attempts:
3 left
💡 Hint
Common Mistakes
Sorting priority queue by start time instead of end time.
Using addition instead of subtraction in comparator.
✗ Incorrect
The priority queue should order intervals by their end time to track earliest finishing meeting.
3fill in blank
hardFix the error in the condition to check if the current meeting can reuse a room.
DSA Java
if (intervals[i].start [1] pq.peek().end) { pq.poll(); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than or less than or equal to instead of greater than or equal to.
Not polling the priority queue when reusing a room.
✗ Incorrect
If the current meeting starts at or after the earliest ending meeting, we can reuse that room.
4fill in blank
hardFill both blanks to add the current interval to the priority queue and return the size as minimum rooms.
DSA Java
pq.[1](intervals[i]); return pq.[2]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using poll or peek instead of add to insert.
Using peek instead of size to get count.
✗ Incorrect
Add the current interval to the queue and return the queue size as the minimum rooms needed.
5fill in blank
hardFill all three blanks to complete the loop that processes all intervals starting from the second one.
DSA Java
for (int i = [1]; i [2] intervals.length; i[3]) { // process intervals }
Attempts:
3 left
💡 Hint
Common Mistakes
Starting loop from 0 instead of 1.
Using <= instead of < in loop condition.
Using i-- instead of i++.
✗ Incorrect
Start from index 1, loop while i is less than length, and increment i by 1 each time.
