#C12142. Find the Second Minimum Value
Find the Second Minimum Value
Find the Second Minimum Value
You are given an array of n integers, where \(2 \le n \le 10^4\) and each integer is in the range \([-10^4, 10^4]\). The array may contain duplicate elements. Your task is to find the second minimum value in the array. The second minimum value is defined as the smallest number that is strictly greater than the minimum value in the array. If there is no such value (i.e. all numbers are the same), output \(-1\).
Example 1:
Input: 5 2 2 3 4 5 Output: 3
Example 2:
Input: 4 1 1 1 1 Output: -1
Example 3:
Input: 4 1 2 2 3 Output: 2
Note: The input is read from standard input and the output should be written to standard output.
inputFormat
The first line contains an integer \(n\) representing the number of elements. The second line contains \(n\) space-separated integers.
outputFormat
Output a single integer, which is the second minimum value of the array if it exists; otherwise, output \(-1\).
## sample5
2 2 3 4 5
3
</p>