Skip to content

Bug Report for two-integer-sum #5990

Description

@ankitkay95

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.

this should fail for
[1,1,1,1,1,4,1,1,1,1,1,7,1,1,1,1,1]
and target 11 when code is like below for c#

public class Solution {
	public int[] TwoSum(int[] nums, int target) {
        var eleAndIdx = new Dictionary<int, int>();
        for (int i=0; i<nums.Length; i++)
        {
            var complement = target - nums[i];
            if (eleAndIdx.ContainsKey(complement))
            {
                return new int[]{eleAndIdx[complement], i};
            }
            else
            {
                eleAndIdx.Add(nums[i], i);
            }
        }
        return new int[]{0};
    }
}

as .Add() on a dictionary in c# with the same key should throw an exception

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