diff --git a/Arrays/mergeOverlappingIntervals.cpp b/Arrays/mergeOverlappingIntervals.cpp new file mode 100644 index 0000000..918d499 --- /dev/null +++ b/Arrays/mergeOverlappingIntervals.cpp @@ -0,0 +1,53 @@ +#include +using namespace std; +/** + * Definition for an interval. + * struct Interval { + * int start; + * int end; + * Interval() : start(0), end(0) {} + * Interval(int s, int e) : start(s), end(e) {} + * }; + */ +vector Solution::merge(vector &A) { + // Do not write main() function. + // Do not read input, instead use the arguments to the function. + // Do not print the output, instead return values as specified + // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details + int i,n=A.size(); + pairp[n]; + for(i=0;i>s; + s.push(p[0]); + for(i=1;is.top().second){ + pairt=s.top(); + s.pop(); + t.second=p[i].second; + s.push(t); + } + } + } + vector>v; + while(!s.empty()){ + v.push_back(s.top()); + s.pop(); + } + sort(v.begin(),v.end()); + int m=v.size(); + A.clear(); + for(i=0;i