09 Sept 2026Go / Python / TypeScriptEasy

N-Repeated Element in Size 2N Array

Find the single value repeated n times in an array of size two n.

Insert values into a set and return the first duplicate; all other values occur once, so the duplicate must be the repeated element.

complexity

O(n) time and O(n) space.

solution files

  • Go n-repeated-element-in-size-2n-array/solution.go
  • Python n-repeated-element-in-size-2n-array/solution.py
  • TypeScript n-repeated-element-in-size-2n-array/solution.ts

Solution files

Gon-repeated-element-in-size-2n-array/solution.go
package main

func repeatedNTimes(nums []int) int {
	seen := map[int]bool{}
	for _, value := range nums {
		if seen[value] {
			return value
		}
		seen[value] = true
	}
	panic("input must contain a repeated element")
}
Pythonn-repeated-element-in-size-2n-array/solution.py
class Solution:
    def repeatedNTimes(self, nums: list[int]) -> int:
        seen: set[int] = set()
        for value in nums:
            if value in seen: return value
            seen.add(value)
        raise ValueError(class="syntax-string">"input must contain a repeated element")
TypeScriptn-repeated-element-in-size-2n-array/solution.ts
function repeatedNTimes(nums: number[]): number {
  const seen = new Set<number>();
  for (const value of nums) { if (seen.has(value)) return value; seen.add(value); }
  throw new Error(class="syntax-string">"Input must contain a repeated element");
}