java 99% solution. one pass O(N) with comments
\tpublic int[][] insert(int[][] intervals, int[] newInterval) {\n        List l = new ArrayList<>();\n        // 1. if an interval end before newInterval start,
\tpublic int[][] insert(int[][] intervals, int[] newInterval) {\n        List<int[]> l = new ArrayList<>();\n        // 1. if an interval end before newInterval start, it can be added to output directly.\n        // 2. if an interval overlapping with new Interval, merge it into new Interval. overlapping if an interval end after new Interval start and start before new Interval end.\n        // 3  after all overlapping intervals processed, add the merged new Interval (or the original new interval if no interval meet #2 condition, i.e. no overlap)\n        // 4. add the rest non overlapping intervals. all the rest have start after new interval end.\n        \n        int i = 0, N = intervals.length;\n        while (i < N && intervals[i][1] < newInterval[0]) // #1\n            l.add(intervals[i++]);\n        \n        while (i < N && intervals[i][0] <= newInterval[1]) { // #2\n            newInterval[0] = Math.min(newInterval[0], intervals[i][0]);\n            newInterval[1] = Math.max(newInterval[1], intervals[i++][1]);\n        }\n        \n        l.add(newInterval); // #3       \n        while (i < N) l.add(intervals[i++]);  // #4\n        return l.toArray(new int[][]{});\n    }
[]