You are given an integer array nums of length 2 * n. It contains n + 1 unique elements, and exactly one of them is repeated n times. Return the element that is repeated n times.
You are given an integer array nums of length 2 * n. It contains n + 1 unique elements, and exactly one of them is repeated n times. Return the element that is repeated n times.
Example 1:
Input: {"nums":[1,2,3,3]}
Output: 3
Constraints:
2≤n≤5000
nums.length==2n
0≤nums[i]≤104
nums contains n + 1 unique elements and one of them is repeated exactly n times.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,2,3,3]}
Half of the 4 slots hold the same value, so two copies must sit within 3 positions of each other somewhere. Try gaps 1, 2 and 3.
gap 1
pairs checked: 0
gap 2
pairs checked: 0
gap 3
pairs checked: 0
10213233
Some run of 4 consecutive slots must hold two copies of the repeated value.