#C14939. Find the Second Largest Element
Find the Second Largest Element
Find the Second Largest Element
You are given a list of integers. Your task is to find the second largest distinct element in the list. If there are fewer than two distinct numbers, output None
.
Formally, given a list \(A = [a_1, a_2, \dots, a_n]\), you need to find the value \(L\) such that:
[ L = \max{ x : x \in A \text{ and } x \neq \max(A) } ]
If such an \(L\) does not exist, print None
.
Note: Input and output should be handled via standard input (stdin) and standard output (stdout), respectively.
inputFormat
The first line contains one integer \(n\) representing the number of elements in the list. The second line contains \(n\) space-separated integers.
outputFormat
Output the second largest distinct integer if it exists; otherwise, output None
.
8
11 27 43 27 36 50 36 50
43