You are viewing a single comment's thread. Return to all comments →
Python 3 -
def absolutePermutation(n, k): a = list(i+1 for i in range(n)) i=0 if k==0: return(a) if n%2 != 0: return([-1]) if n % (k*2) == 0: while(i<len(a)): for _ in range(k): a[i], a[i+k] = a[i+k], a[i] i+=1 i = i+k else: return([-1]) return(a)
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 →
Python 3 -