#K68717. Find the Second Largest Number
Find the Second Largest Number
Find the Second Largest Number
You are given a list of n integers. Your task is to find the second largest unique number in the list. More formally, for a given list \( A = \{a_1, a_2, \dots, a_n\} \), let \( L = \max A \). You need to determine \( S = \max\{ x \in A : x < L \} \). If there is no number less than \( L \) (i.e. the list contains fewer than 2 unique elements), print None
.
Note: The input is provided via standard input and the output should be printed to standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer n (\(0 \le n \le 10^5\)), representing the number of elements.
- The second line contains n space-separated integers.
If n is 0, there will be no integers on the second line.
outputFormat
Output the second largest unique integer from the list. If no such number exists, output None
.
8
3 1 4 1 5 9 2 6
6