Bird
0
0
DSA Cprogramming~10 mins

Merge Overlapping Intervals 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 sort intervals by their start time.

DSA C
int compare(const void *a, const void *b) {
    int *interval1 = (int *)a;
    int *interval2 = (int *)b;
    return interval1[[1]] - interval2[0];
}
Drag options to blanks, or click blank then click option'
A1
B-1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the end time (index 1) instead of start time.
Using an invalid index like 2 or -1.
2fill in blank
medium

Complete the code to check if two intervals overlap.

DSA C
if (intervals[i][0] <= merged[mergedIndex][[1]]) {
    // Overlap detected
}
Drag options to blanks, or click blank then click option'
A2
B0
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing start with start instead of end.
Using wrong indices.
3fill in blank
hard

Fix the error in updating the end time of the merged interval.

DSA C
merged[mergedIndex][1] = (intervals[i][1] > merged[mergedIndex][[1]]) ? intervals[i][1] : merged[mergedIndex][1];
Drag options to blanks, or click blank then click option'
A-1
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using start time index 0 instead of end time index 1.
Using invalid indices.
4fill in blank
hard

Fill both blanks to correctly copy the current interval to merged when no overlap.

DSA C
mergedIndex++;
merged[mergedIndex][[1]] = intervals[i][[2]];
Drag options to blanks, or click blank then click option'
A0
B1
Ci
DmergedIndex
Attempts:
3 left
💡 Hint
Common Mistakes
Using end time index 1 instead of start time 0.
Mixing up indices for source and destination.
5fill in blank
hard

Fill all three blanks to copy both start and end times when no overlap.

DSA C
merged[mergedIndex][[1]] = intervals[i][[2]];
merged[mergedIndex][[3]] = intervals[i][1];
Drag options to blanks, or click blank then click option'
A0
B1
CmergedIndex
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing start and end indices.
Using wrong indices for merged or intervals.