MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / insert

Method insert

LeetCode_problems/Insert Interval/solution.cpp:33–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31class Solution {
32public:
33 vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
34 vector<vector<int>> res;
35
36 int index = 0;
37
38 // Step - 2
39 while(index < intervals.size() && intervals[index][1] < newInterval[0]){
40 res.push_back(intervals[index++]);
41 }
42
43 // Step - 3
44 while(index < intervals.size() && intervals[index][0] <= newInterval[1]){
45 // Step - 3 (a)
46 newInterval[0] = min(newInterval[0], intervals[index][0]);
47
48 // Step - 3 (b)
49 newInterval[1] = max(newInterval[1], intervals[index][1]);
50
51 index++;
52 }
53
54 // Step - 4
55 res.push_back(newInterval);
56
57 // Step - 5
58 while(index < intervals.size()){
59 res.push_back(intervals[index++]);
60 }
61
62 return res;
63 }
64};

Callers 7

mainFunction · 0.45
mindsumMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
reconstructQueueMethod · 0.45
mainFunction · 0.45
makeAnagramFunction · 0.45

Calls 2

minFunction · 0.85
maxFunction · 0.85

Tested by

no test coverage detected