✔️ 100% Fastest Swift Solution, time: O(n), space: O(n).
\nclass Solution {\n    // - Complexity:\n    //   - time: O(n), where n is the number of intervals.\n    //   - space: O(n), where n is the number of intervals
```\nclass Solution {\n    // - Complexity:\n    //   - time: O(n), where n is the number of intervals.\n    //   - space: O(n), where n is the number of intervals.\n\n    func insert(_ intervals: [[Int]], _ newInterval: [Int]) -> [[Int]] {\n        var ans = [[Int]]()\n        var i = 0\n\n        while i < intervals.count, intervals[i][1] < newInterval[0] {\n            ans.append(intervals[i])\n            i += 1\n        }\n\n        var newInterval = newInterval\n        while i < intervals.count, intervals[i][0] <= newInterval[1] {\n            newInterval[0] = min(intervals[i][0], newInterval[0])\n            newInterval[1] = max(intervals[i][1], newInterval[1])\n            i += 1\n        }\n\n        ans.append(newInterval)\n\n        while i < intervals.count {\n            ans.append(intervals[i])\n            i += 1\n        }\n\n        return ans\n    }\n\n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['Swift']