#K88332. Find the Unique Element
Find the Unique Element
Find the Unique Element
You are given an array of N integers in which every element appears exactly three times except for one element that appears exactly once. Your task is to find and print that unique element.
Mathematically, if the array is denoted as \(A = [a_1, a_2, \dots, a_N]\), then for all \(x \in A\) except the unique element \(u\), we have that the frequency of \(x\) is 3. In other words, if \(\text{freq}(x)\) denotes the number of times \(x\) appears in \(A\), then:
[ \text{freq}(x) = 3 \quad \text{for all } x \neq u, \quad \text{and} \quad \text{freq}(u) = 1. ]
It is recommended to use bit manipulation techniques to solve this problem in linear time and constant space.
inputFormat
The first line contains an integer N representing the number of elements in the array. The second line contains N space-separated integers representing the array elements.
Example:
7 2 2 3 2 4 4 4
outputFormat
Output a single integer which is the element that appears exactly once in the array.
Example:
3## sample
7
2 2 3 2 4 4 4
3