Two Sum

Hash map · Look up the missing complement · Easy · about 15 min

Why it matters

Complement lookup is one of the first interview patterns worth recognising.

How it connects

A set remembered that a value existed. A map can also remember where it appeared.

Try first

For each number x, write the exact number you wish had appeared earlier.

Interview cue

I trade extra map space for a linear scan instead of checking every pair.