Back to problems Sign in to unlock
Leetcode
Easy
Arrays
Hash Maps
Sets
N Repeated Element In Size 2n Array
Find the element that appears exactly n times in an array of length 2n where every other element appears once.
Acceptance 100%
Problem Statement
Problem
You are given an integer array nums of length 2n.
Exactly one value appears n times, and every other value appears exactly once.
Return the value that is repeated n times.
Notes
- The repeated value is guaranteed to exist.
- Any valid solution should identify it efficiently without relying on sorting the entire array unless you choose to.
Input Format
- A single integer array
numsof length2n. - The array contains one value repeated exactly
ntimes. - All other values appear once.
Output Format
- Return the integer value that appears
ntimes in the array.
Constraints
2 <= nums.length <= $10^{4}$nums.lengthis even1 <= nums[i] <= $10^{5}$- Exactly one value appears
ntimes - Every other value appears exactly once
Examples
Sample cases returned by the problem API.
Example 1
Input
nums = [1,2,3,3]
Output
3
Explanation
The array length is 4, so n = 2. The value 3 appears twice, and the others appear once.
Example 2
Input
nums = [5,1,5,2,5,3,5,4]
Output
5
Explanation
The array length is 8, so n = 4. The value 5 appears 4 times, which is exactly n.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.