Skip to content

Two Sum does not account for DUPs. #1

Description

@JonPlusPlus

In the current Two Sum solution, the Hash Map does not allow for duplicate numbers in the input array.

Working Example:
Input: nums = [3,2,4], target = 6 Output: [1,2]

  • each output index points to a different value.

Broken Example:
Input: nums = [3,3], target = 6 Output should be: [0,1], but is: [0,0]

  • when the Hash Map made a record of value '3', it could then record the duplicate '3' separately.

I suggest adding either:

  • a method to populate the next available space,
  • or a method to store multiple values under one key.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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