Campaign/Level 11 of 12
mediumHash map1 bug

Two Sum, Same Index Twice

twoSum([3, 2, 4], 6) returns [0, 0] — using the 3 twice.

twoSum(nums, target) returns indices [i, j] (i < j) of two different numbers that add up to target, or [].

Fix the code so every test passes. Keep the function name twoSum.

Test cases

  • twoSum([2,7,11,15], 9) → [0,1]
  • twoSum([3,2,4], 6) → [1,2]
  • twoSum([3,3], 6) → [0,1]
  • twoSum([1,2,3], 7) → []

Hints

each hint costs XP

Stuck? Hints go from a nudge to the exact fix.