Given a sorted array of non-overlapping intervals `intervals` where intervals[i] = [start_i, end_i], and a new interval `newInterval = [start, end]`, insert `newInterval` into `intervals` such that `intervals` is still sorted and non-overlapping. Merge overlapping intervals if necessary and return the resulting array. For example, given intervals = [[1,3],[6,9]] and newInterval = [2,5], the new interval [2,5] overlaps with [1,3], so they merge into [1,5]. The result is [[1,5],[6,9]].
Example 1
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
Output: [[1,5],[6,9]]
Explanation: The new interval [2,5] overlaps with [1,3], merging into [1,5]. [6,9] is unchanged.
Example 2
Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8]
Output: [[1,2],[3,10],[12,16]]
Explanation: [4,8] overlaps [3,5], [6,7] and [8,10] (it touches 8). All four merge into [3,10]. [1,2] and [12,16] do not overlap, so they stay as they are.
Example 3
Input: intervals = [], newInterval = [5,7]
Output: [[5,7]]
Explanation: There are no existing intervals, so the result is just the new interval [5,7].
Since the intervals are already sorted, sweep left to right: collect intervals entirely before the new one, merge all that overlap with it, then collect the rest.
Run checks all cases above. Submit evaluates all test cases.