🎙 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 4 of 10

Inserting a new interval into a list that is already sorted and non-overlapping takes how long?

Inserting a new interval into a list that is already sorted and non-overlapping takes how long?

  1. A.O(n²)
  2. B.O(n log n), because you must sort again
  3. C.O(log n) always
  4. D.O(n), with one walk: before, overlapping, after
Answer & explanation

Correct answer: O(n), with one walk: before, overlapping, after

The list is already in order, so no new sort is needed.

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 →