Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the insertion index.
DSA C
int index = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the end value instead of index.
Initializing with interval values which may not be correct.
✗ Incorrect
The insertion index should be initialized to 0 to start traversing from the beginning of the sorted list.
2fill in blank
mediumComplete the code to check if the current interval ends before the new interval starts.
DSA C
if (intervals[i].end < [1]) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with newInterval.end instead of newInterval.start.
Using the start of the current interval instead of the end.
✗ Incorrect
We check if the current interval ends before the new interval starts to decide if they do not overlap.
3fill in blank
hardFix the error in merging intervals by completing the code to update the new interval's end value.
DSA C
if (intervals[i].start <= newInterval.end) { newInterval.end = [1] > newInterval.end ? [1] : newInterval.end; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the start value instead of the end value.
Adding start and end values incorrectly.
✗ Incorrect
When merging, the new interval's end should be the maximum of its current end and the current interval's end.
4fill in blank
hardFill both blanks to correctly insert the new interval into the result list.
DSA C
result[[1]] = newInterval; return [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the index instead of the result array.
Using incorrect index values for insertion.
✗ Incorrect
The new interval is inserted at the current index, and the updated result array is returned.
5fill in blank
hardFill all three blanks to complete the loop that merges overlapping intervals.
DSA C
for (int i = 0; i [1] intervalsSize; i++) { if (intervals[i].start > newInterval.end) { result[[2]] = newInterval; [3]; } // merging logic }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= in the loop condition causing out-of-bounds errors.
Not returning the result after insertion.
✗ Incorrect
The loop runs while i is less than intervalsSize, inserts newInterval at index, then returns the result.
