You are viewing a single comment's thread. Return to all comments →
def largestPermutation(k, arr): n = len(arr) d = {arr[i]: i for i in range(n)} for i in range(n): if k == 0: break if arr[i] == n - i: continue j = d[n - i] arr[i], arr[j] = arr[j], arr[i] d[arr[i]], d[arr[j]] = i, j k -= 1 return arr
This solution is correct
Seems like cookies are disabled on this browser, please enable them to open this website
Largest Permutation
You are viewing a single comment's thread. Return to all comments →