FreeCareerPath
Build the PrimitiveMedium

Insert Interval

Write `insert_interval(intervals, new_interval)` inserting into a list of non-overlapping intervals sorted by start, merging where necessary, and returning the result sorted. insert([[1,3],[6,9]], [2,5]) -> [[1,5],[6,9]] Three phases: copy everything ending before the new interval starts, absorb everything that overlaps into one merged interval, then copy the rest. Appending and re-sorting works and throws away the ordering you were handed.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Insert Interval" are saved to your account — logging in takes a few seconds.

Insert Interval — FreeCareerPath