← Quiz: Interval Problems: all 10 questions
Quiz: Interval Problems · Question 8 of 10
What does this print? (code)
What does this print?
ms = [[1, 10], [2, 3], [3, 4], [5, 6]]
count, last = 0, -1
for s, e in sorted(ms, key=lambda m: m[1]):
if s >= last:
count += 1
last = e
print(count, len(ms) - count)
- A.1 3
- B.3 1
- C.4 0
- D.2 2
Answer & explanation
Correct answer: 3 1
Sorted by end: [2, 3], [3, 4], [5, 6] fit one after another; [1, 10] must be removed.
Can you get the rest right without peeking?
Take the timed Quiz: Interval Problems quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →