Easy Java ☕Solution || 3ms || Solved using a Single Loop
Complexity\n- Time complexity: O(NlogN)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(N)\n Add your space complexity here, e.g. O(n) \n\n#
# Complexity\n- Time complexity: O(NlogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[][] insert(int[][] intervals, int[] newInterval) {\n        int [][] merged = new int[intervals.length+1][];\n        int c = 0;\n        for (int []i : intervals) {\n            merged[c++] = i;\n        }\n        merged[intervals.length] = newInterval;\n        Arrays.sort(merged , (a,b) -> Integer.compare(a[0], b[0]));\n        List<int []> l1 = new ArrayList<>();\n        for(int [] arr : merged){\n            if(l1.size() == 0) l1.add(arr);\n            else{\n                int [] prevArr = l1.get(l1.size()-1);\n                if(arr[0] <= prevArr[1]){\n                    prevArr[1] = Math.max(prevArr[1] , arr[1]);\n                }\n                else l1.add(arr);\n            }\n        }\n        return l1.toArray(new int[l1.size()][]);\n    }\n}\n```
['Array', 'Java']