#C7929. Single Number (Every Other Element Appears Thrice)
Single Number (Every Other Element Appears Thrice)
Single Number (Every Other Element Appears Thrice)
You are given an array of integers in which every element appears exactly three times except for one element, which appears only once. Your task is to find and output that single integer.
Formally, you are given an array \(A = [a_1, a_2, \ldots, a_n]\). There exists a unique element \(x\) that appears exactly once, while every other element \(y \neq x\) appears exactly three times. Find \(x\).
Example: For \(A = [2, 2, 3, 2]\), the answer is \(3\) because \(2\) appears three times and \(3\) appears once.
inputFormat
The input is given via stdin
and consists of two lines:
- The first line contains an integer \(n\), the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single integer to stdout
, which is the unique element that appears only once.
4
2 2 3 2
3