N-Repeated Element in Size 2N Array - Problem
You are given an integer array nums with the following properties:
nums.length == 2 * nnumscontainsn + 1unique valuesnof the unique values occur exactly once in the array- Exactly one element of
numsis repeatedntimes
Return the element that is repeated n times.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3,3]
›
Output:
3
💡 Note:
Array length is 4 = 2*2, so n=2. Element 3 appears exactly 2 times, while 1 and 2 appear once each.
Example 2 — Different Arrangement
$
Input:
nums = [2,1,2,5,3,2]
›
Output:
2
💡 Note:
Array length is 6 = 2*3, so n=3. Element 2 appears exactly 3 times, while other elements appear once.
Example 3 — Minimum Size
$
Input:
nums = [5,1,5,2,5,3,5,4]
›
Output:
5
💡 Note:
Array length is 8 = 2*4, so n=4. Element 5 appears exactly 4 times, occupying half the array.
Constraints
- 2 ≤ nums.length ≤ 2 * 104
- nums.length is even
- -109 ≤ nums[i] ≤ 109
- nums contains exactly n + 1 unique values
- Exactly one value appears n times
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code