You need to reorder the array into some permutation B such that for every i: ∣ B i - B i+1 ∣≤1 We must decide if such a permutation exists. Key Insight If we sort the array to get C (non-decreasing order): In the sorted array, adjacent numbers are as close as possible. Any other permutation can only make some adjacent differences bigger , never smaller. So: If the sorted array already has some adjacent pair with difference > 1, then no permutation can satisfy the condition. If the sorted array has all adjacent differences ≤ 1, then the sorted array itself is a valid permutation. Therefore, the check is simple: Sort the array. Check all adjacent pairs: If for any i, C[i+1] - C[i] > 1 → print NO. Otherwise → print YES. Algorithm For each test case: Read N and array A. Sort A. For i from 0 to N-2: If A[i+1] - A...