Hashing
TimeO(n)SpaceO(n)
For each number, compute the complement that would reach the target. If we've already seen it, we're done; otherwise store the current number and keep scanning — O(n) with a hash map.
Key idea. Trade space for time — a hash map turns 'have I seen the complement?' into an O(1) lookup, collapsing O(n²) to O(n).
1
Loading…
—