#K37392. Find the Odd Occurrence
Find the Odd Occurrence
Find the Odd Occurrence
You are given an array of integers where exactly one integer occurs an odd number of times while all others occur an even number of times. Your task is to find and output this integer.
You are not allowed to use any library functions specifically aimed at computing frequencies (for example, collections.Counter
in Python). A typical efficient solution uses the bitwise XOR operator. Recall that the XOR of all elements yields the desired result because:
\[
result = a_1 \oplus a_2 \oplus \cdots \oplus a_n
\]
where \(\oplus\) denotes the bitwise XOR operation.
inputFormat
The input is read from standard input (stdin
) and consists of two lines:
- The first line contains an integer n indicating the number of elements in the array.
- The second line contains n space-separated integers representing the array.
outputFormat
The output is a single integer written to standard output (stdout
), which is the number that occurs an odd number of times in the array.
1
1
1