-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
Bug Report for https://neetcode.io/problems/4sum
The test environment is expecting a function called threeSum, but this is fourSum.
This is the solution I am attempting to pass and it keeps failing.
function fourSum(nums, target) {
if (nums.length < 4) return [];
nums.sort((a, b) => a - b);
for (let i = 0; i < nums.length - 3; i++) {
for (let j = i + 1; j < nums.length - 2; j++) {
let left = j + 1;
let right = nums.length - 1;
while (left < right) {
let sum = nums[i] + nums[j] + nums[left] + nums[right];
if (sum === target) {
return [[nums[i], nums[j], nums[left], nums[right]]];
} else if (sum < target) {
left++;
} else {
right--;
}
}
}
}
return [];
}
Metadata
Metadata
Assignees
Labels
No labels