ASAPUtils Logo ASAPUtils
Week 1

Two Sum

Two Sum worked from brute force to the one-pass hash map, with the pattern signal that identifies it, C++ and JavaScript solutions, complexity, and a step-by-step visualizer you can run on your own input.

The problem

Given an array of integers and a target, return the indices of the two numbers that add up to the target. Exactly one valid answer exists, and you may not use the same element twice.

nums = [2, 7, 11, 15], target = 9 -> [0, 1]

Related Problems