Coding Challenge

Find the Duplicate Number

Medium
arraytwo-pointers

Find the repeated number without modifying the array.

The array contains n + 1 integers in the range [1, n] with exactly one repeated number. Return that duplicate without modifying the array.

Examples

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

Output: 2

Constraints

  • Use constant extra space when possible

Preparing your coding workspace...