#K49717. Find the Element with Odd Occurrence
Find the Element with Odd Occurrence
Find the Element with Odd Occurrence
You are given a list of integers in which exactly one integer appears an odd number of times while all others appear an even number of times. Your task is to identify and output this integer.
The problem guarantees that there is exactly one such integer. Use efficient bit manipulation (i.e. XOR operations) to solve this in linear time.
Recall the XOR operation has the property that for any integer \(a\), \(a \oplus a = 0\) and \(a \oplus 0 = a\). Therefore, by XOR-ing all numbers together, all numbers appearing an even number of times cancel out, leaving the one that appears an odd number of times.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer \(n\) denoting the number of elements in the list.
- The second line contains \(n\) space-separated integers.
outputFormat
Output a single line to standard output (stdout) containing the integer that appears an odd number of times.
## sample7
2 3 4 3 2 4 4
4