#K44097. Second Largest Number
Second Largest Number
Second Largest Number
Given a list of integers, your task is to find the second largest unique integer. If the list does not contain at least two unique numbers, output -inf
.
The input will be provided via standard input: the first line contains an integer n representing the number of integers, and the second line contains n space-separated integers.
Your solution must read from standard input and output the correct result to standard output.
Note: In case there is no second largest unique number (i.e., all the numbers are the same), print -inf
.
Mathematically, if we denote the set of unique integers as \( S \) and the largest element as \( M = \max(S) \), then the second largest is \( \max(S \setminus \{M\}) \), if \(|S| \ge 2\). Otherwise, the answer is \(-\infty\).
inputFormat
The first line contains an integer n (\( n \geq 1 \)). The second line contains n space-separated integers.
outputFormat
Print the second largest unique integer. If there is no such number, print -inf
.
9
3 1 4 1 5 9 2 6 5
6