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

๐Ÿ“š Reference Solution

โ–ผ
โŒ˜K Search โŒ˜โ†ฉ Run โŒ˜S Submit