0
0
DSA Pythonprogramming~10 mins

Why Intervals Are a Common Problem Pattern in DSA Python - Test Your Knowledge

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

Complete the code to merge overlapping intervals.

DSA Python
intervals.sort(key=lambda x: x[[1]])
Drag options to blanks, or click blank then click option'
A0
B-1
C2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Sorting by the end time instead of start time.
Using an invalid index like 2 or -1.
2fill in blank
medium

Complete the code to check if current interval overlaps with the last merged interval.

DSA Python
if intervals[i][[1]] <= merged[-1][1]:
Drag options to blanks, or click blank then click option'
A1
B-1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing the end time of current interval instead of start time.
Using wrong index for start time.
3fill in blank
hard

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

DSA Python
merged[-1][1] = max(merged[-1][1], intervals[i][[1]])
Drag options to blanks, or click blank then click option'
A1
B0
C2
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using start time index instead of end time.
Using negative index incorrectly.
4fill in blank
hard

Fill both blanks to create a list of merged intervals.

DSA Python
merged = [intervals[[1]]]
for i in range(1, [2]):
    # merging logic here
Drag options to blanks, or click blank then click option'
A0
Blen(intervals)
C1
Dintervals
Attempts:
3 left
💡 Hint
Common Mistakes
Starting merged list with wrong index.
Looping with incorrect range.
5fill in blank
hard

Fill all three blanks to complete the dictionary comprehension that counts interval overlaps by start time.

DSA Python
overlap_count = { [1]: sum(1 for interval in intervals if interval[[2]] == start) for start in [3] }
Drag options to blanks, or click blank then click option'
Astart
B0
C[interval[0] for interval in intervals]
Dinterval
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in comprehension.
Using wrong index for start time.