Two Sum — one pass with a hash map
For each number, the partner you need is
target − num
. Remember every number you've seen, so you can spot that partner the moment it's already there.
Try:
← Prev
Next →
▶ Play
Reset
nums
seen so far
(value → index)