We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if k !=0 and n% (2*k) !=0:
return [-1]
if k == 0:
return list(range(1, n+1))
return [(u + k if (u-1) % (2*k) + 1 <= k else u - k) for u in range(1, n+1)]
Cookie support is required to access HackerRank
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
def absolutePermutation(n, k):