Campaign/Level 2 of 12
easyTwo pointers1 bug

Sum Zero

A teammate wrote the two-pointer version of Sum Zero, but it returns [0, 0] for some inputs.

Given a sorted array, return the first pair that sums to 0, or undefined if there is none.

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

Test cases

  • sumZero([-4,-3,-2,-1,0,1,2,5]) → [-2,2]
  • sumZero([-3,-2,-1,0,5]) → undefined
  • sumZero([0]) → undefined
  • sumZero([-5,5]) → [-5,5]

Hints

each hint costs XP

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