You are viewing a single comment's thread. Return to all comments →
static int[] absolutePermutation(int n, int k) { int[] per = new int[n]; int d = 1; for (int i = 0, j = 0; i < n; i++, j++) { if (j == k) { d *= -1; j = 0; } int value = i + 1 + k * d; if (value < 1 || value > n) return new int[]{-1}; per[i] = value; } return per; }
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 →