Two Sum — JavaScript easy interview problem
Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assume each input has exactly one solution, and you may not use the same element twice. Return the answer in any order. Prefer a one-pass HashMap approach. Example: `twoSum([2,7,11,15], 9)` → `[0,1]`.
Tags: hashmap, classic
Practice this HashMap & Set problem free in the JS Interview Playground with automated tests and unlockable solutions.