Skip to content

Bug Report for three-integer-sum #5377

@Akhilkumar31

Description

@Akhilkumar31

Bug Report for https://neetcode.io/problems/three-integer-sum

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

class Solution
{
public List<List> threeSum(int[] nums)
{
Arrays.sort(nums);
List<List>ans=new ArrayList<>();
for(int i=0;i<nums.length;i++)
{
if(i>0 && nums[i]==nums[i-1])
continue;
int target=0-nums[i];
int j=i+1,k=nums.length-1;
while(j<k)
{
Listx=new ArrayList<>();
if(nums[j]+nums[k]==target)
{
x.add(nums[i]);
x.add(nums[j]);
x.add(nums[k]);
ans.add(x);
j++;k--;
if(nums[j]==nums[j-1])
j++;
if(nums[k]==nums[k+1])
k--;
}
else if(nums[j]+nums[k]<target)
{
j++;
}
else
{
k--;
}
}
}
return ans;
}
}

submitted this code and it passed
[-4, 2, 2, 2, 2, 2, 2, 2] tried with this custom input and it failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions