Back to Practice Dashboard
Top 150 InterviewEasy

Contains Duplicate

Learn how to solve the 'Contains Duplicate' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

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.

Constraints
  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

Examples

Example 1
Input
nums = [1,2,3,1]
Output
true
Example 2
Input
nums = [1,2,3,4]
Output
false
Need a Hint?
Analyze the input constraints. Try sorting first (O(n log n)) or using a hash map/set to track seen elements in O(n) time.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor