Find the Duplicate Number
Given an array nums containing n + 1 integers where:
- Each integer is in the range [1, n]
- There is only one repeated number, but it may appear more than once
Return the number that appears more than once.
You must solve the problem without modifying the array and using only constant extra space.
Example 1
Input
nums = [1,3,4,2,2]
Output
2
Explanation
The number 2 appears more than once.
Example 2
Input
nums = [3,1,3,4,2]
Output
3
Explanation
The number 3 appears twice, so the duplicate number is 3.
Constraints
Hints:
Hint 1
Think of every array value as pointing to another index.
Hint 2
You can treat the array like a linked list and use Floyd's Cycle Detection Algorithm.
Author & Technical Reviewer
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 10, 2026
Last updated
Aug 11, 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.
Expected Output