easy c++ solution || c++
Intuition\nThe problem requires inserting a new interval into a set of existing intervals while maintaining the intervals\' non-overlapping and sorted nature. T
# Intuition\nThe problem requires inserting a new interval into a set of existing intervals while maintaining the intervals\' non-overlapping and sorted nature. The intuition behind this approach seems to be iterating through the existing intervals and updating the new interval accordingly based on its relationship with each existing interval.\n# Approach\n 1)   Iterate through each interval in the given list of intervals.\n 2)   Check three cases:\n      *  If the current interval ends before the new interval starts, meaning the new interval can be placed after this interval.\n      *  If the new interval ends before the current interval starts, meaning the new interval should be placed before this interval.\n      *  If the intervals overlap, update the new interval\'s start and end to encompass both intervals.\n 3)   After iterating through all intervals, add the updated new interval to the result.\n# Complexity\n- Time complexity:\nO(n), where nn is the number of intervals in the given list.\n- Space complexity:\nO(n)O(n), since the result may contain up to nn intervals.\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n         vector<vector<int>>ans;\n        for(auto &&i:intervals){\n    //  the new interval is after the range of other interval\n            if(i[1]<newInterval[0])ans.push_back(i);\n    // the new interval\'s range is before the other\n            else if(newInterval[1]<i[0]){\n                ans.push_back(newInterval);\n                newInterval=i;//updating the new interval\n            }\n    // the new interval is in the range of the other interval\n            else{\n                newInterval[0]=min(newInterval[0],i[0]);\n                newInterval[1]=max(newInterval[1],i[1]);\n            }    \n        }\n    //At the end after the loop just add the updated newIntervals\n        ans.push_back(newInterval);\n        return ans;\n    }\n};\n```
['C++']