#K84962. Reorder Array to Achieve Consecutive Differences of One
Reorder Array to Achieve Consecutive Differences of One
Reorder Array to Achieve Consecutive Differences of One
You are given an array of n integers. Your task is to determine whether it is possible to reorder the array such that for every consecutive pair of elements, the absolute difference is exactly 1. In other words, after reordering, for every index i (1 ≤ i < n), the condition
[ |a_{i} - a_{i+1}| = 1 ]
must hold true. If such a reordering is possible, output "YES" on the first line and the reordered array (in increasing order) on the second line. Otherwise, output "NO".
Note: The input is given via standard input and the output must be printed to standard output.
inputFormat
The first line of input contains an integer n (1 ≤ n ≤ 105), representing the number of elements in the array. The second line contains n space-separated integers.
outputFormat
If the array can be reordered into a sequence where every adjacent pair differs by 1, print "YES" in the first line, followed by the reordered array (space-separated) in the second line. If not, print "NO".
## sample5
1 3 2 4 5
YES
1 2 3 4 5
</p>