You are viewing a single comment's thread. Return to all comments →
JAVA
public static List<Integer> absolutePermutation(int n, int k) { Integer[] result = new Integer[n]; int idx; for (int value = 1; value <= n; value++) { idx = value - k; if (idx <= n && idx > 0 && result[idx - 1] == null) { result[idx - 1] = value; } else { idx = value + k; if (idx <= n && idx > 0 && result[idx - 1] == null) { result[idx - 1] = value; } else { result = new Integer[1]; result[0] = -1; return Arrays.asList(result); } } } return Arrays.asList(result); }
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 →
JAVA