EASY NC#1 Blind #3 Arrays & Hashing
217. Contains Duplicate
๐ Problem
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
๐ง Visual Learning Aid
1 Model the input into the right structure
2 Choose the core technique and invariant
3 Execute step-by-step with a sample
4 Validate complexity and edge cases
JS/TS Refreshers
- โขArray methods (`push`, `pop`, `shift`, `slice`)
- โขObject/Map/Set usage patterns
- โขFunction parameter and return typing
Logical Thinking Concepts
- โขDefine invariants before coding
- โขCheck edge cases first (`[]`, single element, duplicates)
- โขEstimate time/space before implementation
๐ก Approach
- โ Use Set for O(1) lookups
- โ Compare Set size with array length
- โ Time: O(n), Space: O(n)
๐ ๏ธ Hints & Pitfalls
Hints
- โขUse Set for O(1) lookups
- โขCompare Set size with array length
- โขTime: O(n), Space: O(n)
๐งช Test Cases
Hidden tests on submit: 3
Test Case 1
Not run Input:
containsDuplicate([1, 2, 3, 1]); Expected:
true Test Case 2
Not run Input:
containsDuplicate([1, 2, 3, 4]); Expected:
false Test Case 3
Not run Input:
containsDuplicate([]); Expected:
false ๐ Code Editor
๐ค Output