-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Bug Report for https://neetcode.io/problems/two-integer-sum
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
I am not sure if its a bug or a miss in the problem description. What needs to be done when same number repeats twice in the input list?
Since the description says give the lowest index first, I assumed that If a number repeats, the first occurrence will be kept and solved it. The submission was successful. But when I added a new test case with repeating numbers, the test failed and it was expecting the latest index of repeated value, indicating the multiple occurrence case was not included in the submit test cases.
Now the questions are as follows:
- Is it assumed that there won't be any repeating elements? If so it needs to be mentioned.
- If repeating is allowed, which index to consider? the first occurrence or the last occurrence?
How to reproduce:
Its easy to reproduce. Just add a test case with repeating numbers. And the solution that doesn't override the index in the map when a new value which is repeating comes up. Giving the solution I wrote that does this below:
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
checked = {}
for i in range(len(nums)):
part = target-nums[i]
if part in checked:
return [checked[part],i]
elif nums[i] not in checked:
checked[nums[i]] = i
return []
Removing the elif check will make the code work in current condition