← Practice
Algorithms·medium 18 min 75 XP

Two Sum

Return the indices of the two numbers that add up to a target, using a single pass (not nested loops).

Examples

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

Constraints

  • Keep the required function name so the tests can find it
  • Return a value instead of only logging it
  • Do not mutate inputs unless the challenge asks you to
Two Sum · editor

Code runs in an isolated Web Worker with a 3-second timeout — no DOM access, and it can never hang the page.