Third Distinct Maximum
Print the third largest distinct value; if fewer than three distinct values exist, print the maximum instead.
Input: the first line has N; the second line has N integers.
Output: the third distinct maximum, or the maximum.
Constraints:
- 1 ≤ N ≤ 105
- −109 ≤ ai ≤ 109
Sample Tests
Input 1
5 3 2 1 2 3
Output 1
1
Input 2
2 1 2
Output 2
2
Discussion (opens after you solve — no spoilers before)
No comments yet.