48. Second Largest Element
Core1000 ms256 MBSolved by 0%
Print the second largest distinct value in the array.
Distinct matters: in [5, 5, 3] the largest is 5 and the second largest is 3, not 5.
If every element is the same, so there is no second distinct value, print None.
Constraints - `1 ≤ n ≤ 100000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print one integer, the second largest DISTINCT value, or None if every element is the same.
Input5
3 9 2 9 4
Output4
Notehas the largest value repeated, so the second largest must be a different number
Input3
5 5 5
OutputNone
Notehas no second distinct value at all
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.