🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Interval Problems: all 10 questions

Quiz: Interval Problems · Question 6 of 10

What does this print? (code)

What does this print?

events = []
for s, e in [[1, 5], [2, 6], [4, 8], [7, 9]]:
    events += [(s, 1), (e, -1)]
cur = best = 0
for t, k in sorted(events):
    cur += k
    best = max(best, cur)
print(best)
  1. A.2
  2. B.4
  3. C.3
  4. D.1
Answer & explanation

Correct answer: 3

At time 4, the meetings [1, 5], [2, 6] and [4, 8] are all running.

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 →