You are viewing a single comment's thread. Return to all comments →
Here is my Python solution. I had to import copy in order for this to work.
def largestPermutation(k, arr): indices = {a: b for b, a in enumerate(arr)} for i in range(len(arr)): if k > 0: if arr[i] != len(arr) - i: value = copy.deepcopy(arr[i]) arr[i], arr[indices[len(arr) - i]] = len(arr) - i, arr[i] indices[value] = indices[len(arr) - i] k -= 1 return arr
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 →
Here is my Python solution. I had to import copy in order for this to work.