# Output Limit Exceeded

• I believe my code is correct , but the OJ gives a Output limit exceeded error . What does this really mean ?
This is the first time I am getting this error.`

`````` class Solution
{
public:
vector<vector<int> > threeSum(vector<int> &num)
{
int len = num.size();
vector<vector<int> > v;

if (len < 3) //No triplet exists if no of elements <3
return v;
int i, j, k;
int prev , previ, prevj, prevk;

//First sort the vector
sort(num.begin(), num.end());
previ = prevj = prevk = num[0] - 1; //Be careful if num[0] = INT_MAX

for (i = 0; i < len - 2; i++)
{
if (i != 0 && num[i] == num[i - 1])
continue;

j = i + 1;
k = len - 1;

while (j < k)
{
int sum = num[i] + num[j] + num[k];
if (sum == 0)
{
if (prevj != num[j] || prevk != num[k])  //Atleast one should differ to make a unique triplet from
//existing ones
{
vector<int> t;
t.push_back(num[i]); t.push_back(num[j]); t.push_back(num[k]);
v.push_back(t);
t.clear();
prevj = num[j] , prevk = num[j];
j++; k--;
}
else
{
j++; k--;
}
}
else if (sum > 0)
k--;
else j++;
}
}

//return v;
}
``````

};
`

• This post is deleted!

• I think you didn't remove duplicate triplets resulted from the first for-loop

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