[Java] Greedily absorb overlapping intervals - O(N) time O(1) extra space (explained)
```\n\tpublic int[][] insert(int[][] intervals, int[] newInterval) {\n        List result = new ArrayList<>();\n        \n        int i=0;\n\t\t/ Add all interv
```\n\tpublic int[][] insert(int[][] intervals, int[] newInterval) {\n        List<int[]> result = new ArrayList<>();\n        \n        int i=0;\n\t\t/* Add all intervals ending earlier than the start of newInterval */\n        while(i < intervals.length && intervals[i][1] < newInterval[0]){\n            result.add(intervals[i++]);\n        }\n        \n\t\t/* Greedily absorb any interval that overlaps with newInterval */\n        while(i < intervals.length && intervals[i][0] <= newInterval[1]){\n            newInterval[0] = Math.min(intervals[i][0], newInterval[0]);\n            newInterval[1] = Math.max(intervals[i][1], newInterval[1]);\n            i++;\n        }\n        \n\t\t/* Add newInterval to the result list */\n        result.add(newInterval);\n\t\t\n\t\t/* Add any remaining intervals. These start later than the end\n\t\t   time of newInterval */\n        while(i < intervals.length) result.add(intervals[i++]);\n        \n        return result.toArray(new int[result.size()][]);\n    }
[]