#K50837. Second Largest Unique Integer
Second Largest Unique Integer
Second Largest Unique Integer
You are given a list of integers. Your task is to find the second largest unique integer in the list.
Formally, let \(S\) be the set of distinct integers from the list. If \(|S| < 2\), then the answer is None
. Otherwise, if we sort \(S\) in descending order as \(S = \{s_1, s_2, s_3, \ldots\}\) with \(s_1 > s_2 > s_3 > \cdots\), the answer is \(s_2\).
The input format is as follows: The first line contains an integer n denoting the number of elements. The second line contains n space-separated integers. Your program should output the second largest unique integer, or None
if it does not exist.
inputFormat
The input begins with an integer n (\(1 \leq n \leq 10^5\)), the number of elements in the list, followed by a line containing n space-separated integers. The integers can be positive, negative, or zero.
outputFormat
Output the second largest unique integer. If the list contains fewer than two unique integers, output None
.
5
1 2 3 4 5
4