57. Insert Interval

Practice Insert Interval for free on NudgeCode: Medium, Greedy pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

intervals is a list of non-overlapping [start, end] intervals sorted by start. Insert newInterval, merging any intervals it overlaps (touching ends count as overlapping), and return the result, still sorted and non-overlapping.

Example

intervals = [[1,3],[6,9]], newInterval = [2,5]  ->  [[1,5],[6,9]]

Constraints