Back to January Back to Year 2026
EASY 02 Jan 2026 View on LeetCode

961. N-Repeated Element in Size 2N Array

</> Solution

/**
 * Problem: LeetCode 961 - N-Repeated Element in Size 2N Array
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
import java.util.HashSet;
import java.util.Set;

class Solution {
    public int repeatedNTimes(int[] nums) {
        Set<Integer> seen = new HashSet<>();
        for (int num : nums) {
            // Because all other elements occur strictly once,
            // the very first duplicate found is guaranteed to be our answer!
            if (seen.contains(num)) {
                return num;
            }
            seen.add(num);
        }
        return -1; // Fallback to satisfy compiler (unreachable per constraints)
    }
}

TIME COMPLEXITY

O(N)

SPACE COMPLEXITY

O(N)

TOPICS

Array Hash Table