Bird
0
0
DSA Cprogramming~10 mins

Insert Interval into Sorted List in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the insertion index.

DSA C
int index = [1];
Drag options to blanks, or click blank then click option'
Aintervals[0].end
BnewInterval.end
Cintervals[0].start
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the end value instead of index.
Initializing with interval values which may not be correct.
2fill in blank
medium

Complete 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'
AnewInterval.start
BnewInterval.end
Cintervals[i].start
Dintervals[i].end
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.
3fill in blank
hard

Fix 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'
Aintervals[i].end
Bintervals[i].start
CnewInterval.start
DnewInterval.start + intervals[i].end
Attempts:
3 left
💡 Hint
Common Mistakes
Using the start value instead of the end value.
Adding start and end values incorrectly.
4fill in blank
hard

Fill 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'
Aindex
Bindex + 1
Cresult
Dresult + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the index instead of the result array.
Using incorrect index values for insertion.
5fill in blank
hard

Fill 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'
A<
Bindex
Creturn result
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= in the loop condition causing out-of-bounds errors.
Not returning the result after insertion.