#K2426. Unique Element in Triplets
Unique Element in Triplets
Unique Element in Triplets
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 and output that unique element.
Constraints:
- $1 \leq n \leq 3 \times 10^4$ where n is the number of elements in the array.
- $-2^{31} \leq \text{nums}[i] \leq 2^{31} - 1$ for all valid i.
- Every element except one appears exactly three times.
Input Format: 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.
Output Format: Output a single integer — the element that appears only once.
Example:
Input: 4 2 2 3 2</p>Output: 3
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains a single integer n ($1 \leq n \leq 3 \times 10^4$), the number of elements in the array.
- The second line contains n space-separated integers, where each integer satisfies $-2^{31} \leq nums[i] \leq 2^{31}-1$. All elements except one appear exactly three times.
outputFormat
The output should be a single integer printed to standard output (stdout), representing the unique element that appears only once.
## sample4
2 2 3 2
3