Skip to content
BASA DSA

Find The Duplicate Number

MediumLinked List

An array of n+1 integers contains values 1..n, with exactly one value appearing multiple times. Return that value without modifying nums, using constant auxiliary space.

Example 1

Input
nums = [2,1,4,3,2]
Output
2

Explanation

2 occurs twice while the other values appear once.

Example 2

Input
nums = [1,1]
Output
1

Explanation

The smallest valid array repeats 1.

Example 3

Input
nums = [3,3,3,3]
Output
3

Explanation

3 is the one repeated value even though its multiplicity is four.

Constraints

  • 2 <= len(nums) <= 100001
  • One distinct value is repeated; its multiplicity may exceed two

Function contractfindDuplicateArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…