Bird
0
0
DSA Cprogramming~10 mins

Non Overlapping Intervals Minimum Removal 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 end time.

DSA C
int compare(const void *a, const void *b) {
    int *intervalA = *(int **)a;
    int *intervalB = *(int **)b;
    return intervalA[[1]] - intervalB[[1]];
}
Drag options to blanks, or click blank then click option'
A-1
B0
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by start time instead of end time.
Using wrong index for end time.
2fill in blank
medium

Complete the code to initialize the count of non-overlapping intervals.

DSA C
int count = 1;
int prev_end = intervals[0][[1]];
Drag options to blanks, or click blank then click option'
A1
B2
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using start time instead of end time.
Initializing count to 0 instead of 1.
3fill in blank
hard

Fix the error in the condition to check if intervals overlap.

DSA C
for (int i = 1; i < intervalsSize; i++) {
    if (intervals[i][0] >= [1]) {
        count++;
        prev_end = intervals[i][1];
    }
}
Drag options to blanks, or click blank then click option'
Aintervals[i][1]
Bcount
Cintervals[i][0]
Dprev_end
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing start time with start time.
Using wrong variable in condition.
4fill in blank
hard

Fill both blanks to calculate the minimum number of intervals to remove.

DSA C
int minRemoval = [1] - [2];
return minRemoval;
Drag options to blanks, or click blank then click option'
AintervalsSize
Bcount
Cprev_end
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Subtracting wrong variables.
Returning count instead of minimum removals.
5fill in blank
hard

Fill all three blanks to complete the function for minimum removals.

DSA C
int eraseOverlapIntervals(int** intervals, int intervalsSize, int* intervalsColSize) {
    qsort(intervals, intervalsSize, sizeof(int*), [1]);
    int count = 1;
    int prev_end = intervals[0][[2]];
    for (int i = 1; i < intervalsSize; i++) {
        if (intervals[i][0] >= [3]) {
            count++;
            prev_end = intervals[i][1];
        }
    }
    return intervalsSize - count;
}
Drag options to blanks, or click blank then click option'
Acompare
B1
Cprev_end
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function name in qsort.
Using wrong indices for start/end times.
Incorrect overlap condition.