Single Number (XOR)
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
LEARN BY DOINGPut your intuition to work3 steps
Single Number (XOR)
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.Sample case — your program reads stdin and prints to stdout.
Need a hand?
Start with a small test case. Hints progress from an idea to an explanation and, when requested, code.
Starter 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