The N-Repeated Element in Size 2N Array problem gives you an array of size 2N containing N+1 unique values — all values appear exactly once except one value that appears exactly N times. Find the N-repeated element. This easy coding problem has multiple O(n) solutions leveraging the high frequency of the repeated element.
Akamai and Google ask this simple problem to quickly assess whether candidates can reason about element frequencies. With N repetitions out of 2N elements, the repeated element is extremely dense. The array and hash table interview pattern is straightforward here, but the problem also has elegant O(1) space solutions.
Hash set or pigeonhole observation. Hash set approach: traverse the array; return the first element seen twice. Pigeonhole: with N elements repeated among 2N positions, check every pair arr[i] == arr[i+1] or arr[i] == arr[i+2]. The repeated element must appear adjacent or within 2 positions due to pigeonhole principle.
Array: [2, 1, 3, 2, 2, 2]. N=3, size=6. The element 2 appears 3 times.
arr[i]==arr[i+2] check needed for pigeonhole).When an element appears N times in an array of size 2N, it must appear in at least one of every two consecutive pairs — use the pigeonhole principle. This O(1) space observation is impressive in interviews. Practice recognizing when high-frequency guarantees allow O(1) space solutions instead of hash maps. These density-based observations are common in array frequency problems.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Anagram Mappings | Easy | Solve | |
| Find the Number of Good Pairs I | Easy | Solve | |
| Distribute Candies | Easy | Solve | |
| Max Pair Sum in an Array | Easy | Solve | |
| Minimum Number of Operations to Make Elements in Array Distinct | Easy | Solve |