You are viewing a single comment's thread. Return to all comments →
def absolutePermutation(n, k): v = 1 ans = [] used = set() while v <= n: d1, d2 = v - k, v + k if d1 > 0 and d1 not in used: ans.append(d1) used.add(d1) elif d2 <= n and d2 not in used: ans.append(d2) used.add(d2) else: return [-1] v += 1 return ans
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 →