Beautiful Permutation
Output a permutation of 1..N where no two adjacent values differ by exactly 1 — specifically, print all EVEN numbers ascending, then all ODD numbers ascending. If no such permutation exists (N = 2 or 3), print NO SOLUTION.
Input: one integer N.
Output: the required permutation, or NO SOLUTION.
Constraints:
- 1 ≤ N ≤ 105
Sample Tests
Input 1
5
Output 1
2 4 1 3 5
Input 2
3
Output 2
NO SOLUTION
Discussion (opens after you solve — no spoilers before)
No comments yet.