Runtime error! Can someone help with this?


bool comp(Interval a,Interval b)
return a.start<b.start;
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
for (auto it = A.begin(); it < A.end(); ++it)
if(it->end > (it+1)->start)

 return A;



watch your for loop you are traversing from A.begin() to A.end() but inside the loop you are accessing (it+1) which throws runtime error


How can i fix this? how to iterate upto last but second element?


change to this it<A.end() -1