LeetCode-Feedback / LeetCode-Feedback

675 stars 332 forks source link

Missing Test Case - 1. Two Sum #24389

Closed navedrasul closed 1 month ago

navedrasul commented 1 month ago

LeetCode Username

navedrasul

Problem Number, Title, and Link

  1. Two Sum https://leetcode.com/problems/two-sum/

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

The function should return [-1, -1] when there is no pair whose sum is equal to the given 'target'. Also, there is no constraint for this.

Language Used for Code

TypeScript

Code used for Submit/Run operation

function twoSum(nums: number[], target: number): number[] {
    let len = nums.length;
    for (let i = 0; i < len-1; i++) {
        for(let j = i + 1; j < len; j++) {
            if(nums[i] + nums[j] === target) {
                return [i, j];
            }
        }
    }
    return [-1, -1];
};

Expected behavior

There was no case covering the case when there is no pair whose sum is equal to the given 'target'. The function should return [-1, -1] in such a case.

Screenshots

No response

Additional context

No response

exalate-issue-sync[bot] commented 1 month ago

LeetCode Support commented: Hello navedrasul,

Thank you for reaching out regarding your concerns with the "Two Sum" problem. The problem statement guarantees that each input will have exactly one solution, which means that there isn't a scenario where there won't be a pair of numbers adding up to the target. Therefore, your implementation accommodating for a return of [-1, -1] when no valid pairs exist isn't necessary for this problem.

I recommend reviewing the problem constraints carefully, as they specify that only one valid answer exists for the given input. This should help clarify the expected behavior of your solution. If there are other questions or if you'd like further clarification, feel free to reach out. We're here to help!

Best regards, LeetCode Support Team