#C12964. Second Largest Element
Second Largest Element
Second Largest Element
You are given a list of integers. Your task is to find the second largest distinct element in the list. If the list has fewer than two distinct elements, output None
.
The input consists of an integer n representing the number of elements, followed by a line of n space-separated integers. Your program should print the second largest distinct number, or None
if it does not exist.
The formula to describe the problem is as follows:
Let \(A = \{a_1, a_2, \ldots, a_n\}\) be the set of input numbers. If \(|\{a_1, a_2, \ldots, a_n\}| < 2\), output \(None\); otherwise, output the second greatest element in \(\{a_1, a_2, \ldots, a_n\}\).
inputFormat
The first line contains an integer n, the number of elements. The second line contains n space-separated integers.
outputFormat
Print a single line containing the second largest distinct integer, or 'None' if it doesn't exist.## sample
6
4 1 7 3 2 7
4