# Output Limit Exceeded (but VC passed)?

• class Solution {
public:
vector<Interval> insert(vector<Interval> &intervals, Interval newInterval) {
int i=-1,N=intervals.size();
vector<Interval> viv;
if(N==0)
{
viv.push_back(newInterval);
return viv;
}
while(i+1<N && intervals[i+1].start<=newInterval.start)
{
i++;
viv.push_back(intervals[i]);
}
bool gluelefttoi=(i>-1 && intervals[i].end-1+1>=newInterval.start);
if(gluelefttoi)
viv.back().end=newInterval.end;
else
viv.push_back(newInterval);
int j=i;
while(j<N && intervals[j].end-1<newInterval.end-1)
j++;
bool gluerighttoj=(j<N && intervals[j].start-1<=newInterval.end-1);
int of=0;
if(gluerighttoj)
{
viv.back().end=intervals[j].end;
of=1;
}
for(int k=j+of;k<N;k++)
viv.push_back(intervals[k]);
return viv;
}
};

//Can anyone give a clue why the above code get "Output Limit Exceeded"? really confused since it's passed many test cases in Visual C++. Thanks.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.