Medium · Arrays

Find duplicate number

Given an array nums of n + 1 integers, each in the range 1..n, in which exactly one value repeats (possibly more than twice), return that repeated value without modifying the array.

Examples

Example 1

[1,3,4,2,2]

Output: dup = 2

Example 2

[3,1,3,4,2]

Output: dup = 3

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Arrays problems