#C2146. Rearrange Array
Rearrange Array
Rearrange Array
Given an array of n integers, determine whether it is possible to rearrange its elements so that the absolute difference between any two consecutive elements is at most 1. In other words, you need to reorder the array so that for each consecutive pair \(a_i\) and \(a_{i+1}\), the following holds:
\(|a_i - a_{i+1}| \leq 1\)
If such a rearrangement exists, output Possible
; otherwise, output Not Possible
.
inputFormat
The first line contains an integer n, representing the number of elements in the array. The second line contains n space-separated integers.
outputFormat
Output a single line containing either "Possible" or "Not Possible" based on whether the array can be rearranged to meet the condition.## sample
6
3 1 2 2 3 1
Possible
</p>