PythonEasyArrays10 min

Find the second largest distinct value

Repeated occurrences do not create additional ranks. Print NONE if fewer than two distinct values exist. Interviewers use this problem to assess track two distinct maxima rather than sorting.

Input

First line: n. Second line: n space-separated integers (empty when n = 0).

Output

Print the result on one line; print an empty line for an empty string.

Constraints

0 <= n <= 100000; -10^9 <= each value <= 10^9.

Example

Input

5
4 8 8 2 6

Output

6

Example 2 input

3
1000000000 -1000000000 0

Output

0

Extreme signed values must not conflict with sentinel state.

Public test cases (2)

  • Input

    5
    4 8 8 2 6

    Expected output

    6
  • Input

    4
    -5 -2 -9 -2

    Expected output

    -5
Hints (2)
  1. Identify the state needed to avoid repeated work.
  2. Track two distinct maxima rather than sorting.

Target complexity: time O(n) · space O(1)

Your solution

Checking runner availability…

Reference solution

Sign in for solution
All Python programs