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.
defabsolutePermutation(n,k):# Write your code here ifk==0:return[iforiinrange(1,n+1,1)]elifn%(2*k)!=0:return[-1]else:ifk==1:return[i+1ifi%2!=0elsei-1foriinrange(1,n+1,1)]elifk<=n/2andn%k==0:a=1flag=Trueans=[]whilea<=n:ifflag:ans.append(a+k)else:ans.append(a-k)a+=1ifa%k==1:flag=notflagreturnanselse:return[-1]
Absolute Permutation
You are viewing a single comment's thread. Return to all comments →
Python 3