You are viewing a single comment's thread. Return to all comments →
def absolutePermutation(n, k): if k == 0: return [i+1 for i in range(n)] lexMap = {} for i in range(n): lexMap[i+1] = True res = [] for i in range(1, n+1): if i-k in lexMap: res.append(i-k) del lexMap[i-k] elif i+k in lexMap: res.append(i+k) del lexMap[i+k] return res if len(lexMap) == 0 else [-1]
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 →
Python3 Solution