✅C++ || ✅Same Logic of Merge Intervals || ✅2 Pointers || ✅Comments Added
Merge Interval Problem\n### https://leetcode.com/problems/merge-intervals/\n\n\nclass Solution {\npublic:\n    vector<vector<int>> insert(vector<vector<int>>& i
### Merge Interval Problem\n### https://leetcode.com/problems/merge-intervals/\n\n```\nclass Solution {\npublic:\n    vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) \n    {\n        // just remember the merge intervals problem\n        // try to change this problem into that\n        \n        // add newInterval to the intervals\n        intervals.push_back(newInterval);\n        \n        // now sort this\n        sort(intervals.begin(),intervals.end());\n        \n        // now use the same logic that we used in merge intervals\n        vector<vector<int>> ans;\n        int n = intervals.size();\n        int i=0,j=1;                                // using 2 pointers\n        ans.push_back(intervals[i]);                // very first interval\n        \n        while(j<n)\n        {\n            // if my new interval is not overalpping with previous one then just add this\n            if(intervals[j][0]>ans[i][1])\n            {\n                i++;                                // move previous pointer\n                ans.push_back(intervals[j]);\n            }\n            // if it is overlapping then update prev second by curr second\n            else\n            {\n                ans[i][1] = max(ans[i][1],intervals[j][1]);\n            }\n            \n            j++;\n        }\n        \n        return ans;\n    }\n};\n```
[]