Back to course home
0% completed
Vote For New Content
We can change a bit the Insert Interval solution to make it in-place (constant s...
Athanasios Petsas
Feb 9, 2022
We can change a bit the Insert Interval solution to make it in-place (constant space). Code in C++ here: {code} static vector insert (vector & intervals, Interval given) { if (intervals.size() == 0) { // or intervals.empty() intervals.push_back(given); return intervals; } // iterate throught all the intervals int i=0; while (i < intervals.size() && intervals[i].end < given.start) { // skip non-overlapping intervals with given i++; }
// merge all intervals that overlap with given while (i < intervals.size() && intervals[i].start
0
0
Comments
Comments
On this page