You are viewing a single comment's thread. Return to all comments →
Another way to look at it is if n % (2*k) is not ZERO, print -1. That's because you'll need to "shuffle" groups of 2*k elements.
For example, when n = 8 and k = 2, you'll start off with [1,2,3,4,5,6,7,8] and shuffle groups of 4 like this:
1 and 3
2 and 4
-
5 and 7
6 and 8
...
The approach works in this case because 8 is divisible by 4. Or more generally, it will work when n is divisble by 2*k.
Seems like cookies are disabled on this browser, please enable them to open this website
Absolute Permutation
You are viewing a single comment's thread. Return to all comments →
Another way to look at it is if n % (2*k) is not ZERO, print -1. That's because you'll need to "shuffle" groups of 2*k elements.
For example, when n = 8 and k = 2, you'll start off with [1,2,3,4,5,6,7,8] and shuffle groups of 4 like this:
1 and 3
2 and 4
-
5 and 7
6 and 8
...
The approach works in this case because 8 is divisible by 4. Or more generally, it will work when n is divisble by 2*k.