if (!intervals.size()) return {newInterval}; int i = 0, n = intervals.size(); vector ans; // condition 1 - continue to merge as long as there is no overlap while (i < n && intervals[i][1] < newInterval[0]) { ans.push_back(intervals[i]); i++; } // condition 2 - overlap conflict - resolve by merging while (i < n && intervals[i][0]
@@MadWe582 ahh yes you are correct.. this should be done after the 2nd while loop to insert the newly merged intervals. I will not fix it in, but let whoever is reading this solution figure it out where to insert it :)
This ignores the requirement that you have to modify the intervals array in place and return it. You're not supposed to create a new array with the new intervals. I'm not saying that it won't pass, but it technically doesn't meet the requirements the problem is asking.
Tricky one to explain! I appreciate your efforts as always
if (!intervals.size()) return {newInterval};
int i = 0, n = intervals.size();
vector ans;
// condition 1 - continue to merge as long as there is no overlap
while (i < n && intervals[i][1] < newInterval[0]) {
ans.push_back(intervals[i]);
i++;
}
// condition 2 - overlap conflict - resolve by merging
while (i < n && intervals[i][0]
need to push the newInterval to ans before the last while loop
@@MadWe582 ahh yes you are correct.. this should be done after the 2nd while loop to insert the newly merged intervals.
I will not fix it in, but let whoever is reading this solution figure it out where to insert it :)
This ignores the requirement that you have to modify the intervals array in place and return it. You're not supposed to create a new array with the new intervals. I'm not saying that it won't pass, but it technically doesn't meet the requirements the problem is asking.
It literally says:
"Note that you don't need to modify intervals in-place. You can make a new array and return it."