#K1641. Second Smallest Number
Second Smallest Number
Second Smallest Number
Given an array of integers, your task is to find the second smallest distinct number in the array. If the array does not have at least two unique numbers, print -1
.
In other words, let \( S \) be the sorted set of the unique numbers in the input array. You need to output: \[ \text{result} = \begin{cases} S_{2} & \text{if } |S| \ge 2, \\ -1 & \text{if } |S| < 2. \end{cases} \]
The input is given via standard input and the result should be printed on standard output.
inputFormat
The input consists of two lines:
- The first line contains a single integer \( n \) representing the number of elements in the array.
- The second line contains \( n \) integers separated by spaces.
outputFormat
Output a single integer which is the second smallest distinct number in the array. If there are fewer than two unique numbers, output -1
.
7
4 3 2 5 8 1 6
2