Find the Second Largest Element
Easyjavapythonccppjavascript
Given an array that contains at least two different values, find the second largest distinct element.
Input Format
The first line contains an integer N. The second line contains N space-separated integers. At least two distinct values are present.
Output Format
Print the second largest distinct element.
Example 1
Input
5 10 5 8 10 3
Output
8
Explanation: The largest value is 10; the next largest distinct value is 8.
- 2 <= N <= 100000
- -1000000000 <= A[i] <= 1000000000
- At least two distinct elements exist.