Leetcode 57: Insert Interval

This was a little bit fiddly with some edge cases to consider. Iterate through the intervals array attempting to insert the new range or merge it. So at every step we need to check if the new range is before the current range or overlapping. There are a few different overlap conditions to consider. Also check to see if we need to insert the new entry at the back of the array.

Code from above:
https://gist.github.com/adamkorg/6fcf6ef13a04ab6967c6af3b4762be72
And, slightly cleaned up version:

This entry was posted in programming and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.