A hash map (dictionary) gives O(1) average lookups, inserts, and deletes. Trading O(n) memory for speed turns many O(n²) algorithms into O(n) by replacing repeated scans with instant lookups.
The idea
Instead of searching a list each time, store seen values in a hash map and check membership in constant time.
Example: two-sum in O(n)
():
seen = {}
i, x (nums):
need = target - x
need seen:
(seen[need], i)
seen[x] = i
two_sum([, , , ], )
