Skip to content

ORIGINAL CODING QUESTION

Runner-up distinct score

Return the second largest DISTINCT score, or -101 if fewer than two distinct scores exist.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n integer values. Print one integer as described.

Constraints

1 ≤ n ≤ 200; -100 ≤ value ≤ 100. Inputs contain exactly the stated values.

Example 1

Input

5 4 9 9 2 7

Output

7

Distinct top scores are 9 and 7.

Example 2

Input

3 8 8 8

Output

-101

No second distinct score exists.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

Repeated maximum values do not form a runner-up.

Hint 2

Maintain two distinct candidates.

Hint 3

Update the maximum and runner-up together when a larger score arrives.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →