You are viewing a single comment's thread. Return to all comments →
index={} n=len(arr) for i in range(n): index[arr[i]]=i swap=i=0 while swap<k and i<n: if arr[i]<n-i: idx=index[n-i] arr[i],arr[idx]=arr[idx],arr[i] index[arr[idx]]=idx index[n-i]=i swap+=1 i+=1 return arr
Largest Permutation
You are viewing a single comment's thread. Return to all comments →