insert-interval.sh — zsh
arraysintervals

Given a sorted list of non-overlapping intervals intervals and one additional interval new_interval, insert the new interval into the correct position and merge every overlap created by that insertion. Return the resulting intervals in sorted order.

Examples
Example 1
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
Output: [[1,5],[6,9]]
Example 2
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
Output: [[1,2],[3,10],[12,16]]
Example 3
Input: intervals = [], newInterval = [5,7]
Output: [[5,7]]
🔒 6 hidden
Running will execute all 9 cases, including 6 hidden ones.