Embercode
✕
The STLCoding problems

The STL: coding problems

Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.

0 of 8 solved

  • A teacher writes down the scores from a quiz. Some scores repeat. She wants the second highest score that is different from the top score.

    Read the scores and print that value. If every score is the same, or there is only one score, print -1.

    Input. The first line holds n, the number of scores (1 to 100000). The second line holds n integers, each between -1000000000 and 1000000000.

    Output. One integer: the second largest distinct value, or -1 if there are fewer than two distinct values.

    Example 1 input

    5
    3 9 2 9 7
    

    Output

    7
    

    Example 2 input

    3
    4 4 4
    

    Output

    -1