ExamAdda Logo

Contains Duplicate

Easy

Given an integer array nums, return true if any value appears at least twice in the array.

Return false if every element appears only once.

Example 1

Input

n = 4
nums = [1,2,3,1]

Output

true

Explanation

The value 1 appears twice.

Example 2

Input

n = 4
nums = [1,2,3,4]

Output

false

Explanation

Every element appears exactly once.

Constraints

1 <= nums.length <= 100000
-1000000000 <= nums[i] <= 1000000000

Hints:

Hint 1

Use a set to keep track of the elements that have already appeared.

Hint 2

If an element is already present in the set, a duplicate exists. Otherwise, add the element to the set.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 19, 2026

Last updated

Aug 20, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output