All tasks
Mediumarraysloopssorting

Second Largest Value

Time limit 2 s · Memory 64 MBAcceptance: —Solved by: 0

Statement

The first line contains n, the second line contains n integers. Print the second largest among the distinct values. It is guaranteed that the array contains at least two distinct values. For example, for 5 5 4 4 the answer is 4.

Examples

Example 1
Input
5
3 9 2 9 1
Output
3
Example 2
Input
4
5 5 4 4
Output
4

Constraints

  • 2 ≤ n ≤ 10^5
  • -10^9 ≤ a_i ≤ 10^9
  • At least two distinct values exist
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.