Contains Duplicate

Hash set · Remember what you have seen · Warm-up · about 12 min

Why it matters

A set turns repeated searching into fast membership checks.

How it connects

You carried one number forward. Now carry a growing memory of values you have seen.

Try first

Ask: what would make you able to spot a repeat immediately?

Interview cue

A hash set gives average O(1) membership checks, so the full scan is O(n).