Hashing
TimeO(n)SpaceO(n)
Decide whether any value appears twice — by asking a set “have I seen you?” before keeping each value.
Key idea. Lookup-then-insert. The set holds every value already walked past, so one membership question settles the current value against the whole prefix — the work a nested loop pays a comparison at a time.
1
Loading…
—