Module 4 · Hashing · Hashing

Two sum

For every number, its partner is target - nums[i]. Remember each number's index in a HashMap as you go, and a partner seen earlier is found in O(1) — one pass instead of trying every pair.

seenAt maps each value seen to its index.

Approach