Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new interval with given start and end.
DSA C#
var newInterval = new Interval([1], end);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'end' as the start value.
Using a fixed number like 0 instead of the variable.
Using intervals.Count which is unrelated here.
✗ Incorrect
We create a new interval starting at the given 'start' value and ending at 'end'.
2fill in blank
mediumComplete the code to add the current interval to the result list.
DSA C#
result.[1](intervals[i]);Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove or Clear instead of Add.
Using Insert without specifying index.
✗ Incorrect
We add the current interval to the result list using the Add method.
3fill in blank
hardFix the error in the condition to check if intervals[i] ends before newInterval starts.
DSA C#
while (i < intervals.Count && intervals[i].End [1] newInterval.Start) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which checks the opposite.
Using '>=' or '<=' which may cause incorrect overlap detection.
✗ Incorrect
We check if the current interval ends before the new interval starts using '<'.
4fill in blank
hardFill both blanks to merge intervals overlapping with newInterval.
DSA C#
newInterval.Start = Math.[1](newInterval.Start, intervals[i].Start); newInterval.End = Math.[2](newInterval.End, intervals[i].End);
Attempts:
3 left
💡 Hint
Common Mistakes
Using Max for start or Min for end which reverses the logic.
Using Abs or Round which are unrelated.
✗ Incorrect
We take the minimum start and maximum end to merge overlapping intervals.
5fill in blank
hardFill all three blanks to insert the merged newInterval and add remaining intervals.
DSA C#
result.[1](newInterval); while (i < intervals.Count) { result.[2](intervals[i]); i[3]1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove instead of Add.
Using '--' to decrement i which causes infinite loop.
✗ Incorrect
We add the merged interval, then add remaining intervals, incrementing i by 1 each time.
