This problem follows the Hash Set pattern, commonly found in the Arrays & Hashing category. Recognizing this pattern is key to solving it efficiently in an interview setting.
Add each element to a set. If it already exists, return true.
A hash set gives O(1) lookup — checking 'have I seen this before?' is the core operation.
seen = new Set()
for num in nums:
if num in seen:
return true
seen.add(num)
return falsePractice Contains Duplicate and similar Arrays & Hashing problems with flashcards. Build pattern recognition through active recall.
Practice this problem