#K64777. Find the Unique Element
Find the Unique Element
Find the Unique Element
You are given an array of integers where every element appears exactly three times except for one element which appears only once. Your task is to find that unique element.
More formally, given an array \( nums \) of length \( n \), where every element appears exactly three times except for one, you need to output the element that appears only once.
The solution should work in linear time complexity \( O(n) \) and without using extra memory for a hash table.
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains an integer \( n \) representing the number of elements in the array.
- The second line contains \( n \) space-separated integers.
outputFormat
Output a single integer to standard output (stdout) which is the unique element appearing exactly once.
## sample7
2 2 3 2 4 4 4
3