Single Number (XOR)
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Sample case — your program reads stdin and prints to stdout.
Given a non-empty array where every element appears twice except for one, find that single element.
Use XOR: a ^ a = 0, a ^ 0 = a. XOR all numbers together.
Example: [4,1,2,1,2] → 4 (1^1=0, 2^2=0, 4^0=4)
Input format
Line 1: n. Line 2: n space-separated integers.
Output format
The single number.
Constraints
1 ≤ n ≤ 3×10⁴, n is odd