#K52862. First Unique Element
First Unique Element
First Unique Element
You are given a list of integers which may contain both negative and positive values. Your task is to find the first unique element in the list, i.e. the first element that appears exactly once. If no such element exists, print None
.
The input is given via standard input. The first line contains a single integer n representing the number of elements in the list. The second line contains n space-separated integers.
Mathematical Explanation: Let \(a_1, a_2, \ldots, a_n\) be the list of integers. We need to find the smallest index \(i\) such that \(\#\{j \mid a_j = a_i\} = 1\). If no such index exists, return \(\text{None}\).
inputFormat
The first line contains an integer n
(\(0 \le n \le 10^5\)), the number of integers in the list. The second line contains n
space-separated integers. If n
is 0, the second line will be empty.
outputFormat
Print the first unique integer from the list. If there is no unique integer, print None
.
6
4 5 1 2 0 4
5
</p>