Find Second Minimum
EasyPractice library · +10 XPbasicssortingconditionals
Given a list of N integers, find and print the second smallest distinct integer in the list. If there are fewer than two distinct integers, print -1.
Input
The first line contains an integer N (1 <= N <= 1000). The second line contains N space-separated integers.
Output
Print a single integer: the second smallest distinct number in the list, or -1 if it doesn't exist.
Constraints
1 <= N <= 1000. Integers are between -1000 and 1000.
Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests
Example 1
Input
5 1 5 2 5 2
Output
2
The distinct numbers are 1, 2, 5. The second smallest is 2.
Example 2
Input
3 10 10 10
Output
-1
There is only one distinct number (10), so the output is -1.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 1 5 2 5 2
Example 2 input
3 10 10 10