You are viewing a single comment's thread. Return to all comments →
Python
def countSwaps(arr, r): arr = arr.copy() target = sorted(arr, reverse = r) inds = {v:i for i,v in enumerate(target)} i = 0 count = 0 while i < len(arr) and arr != target: while arr[i] != target[i]: ind = inds[arr[i]] arr[i], arr[ind] = arr[ind], arr[i] count += 1 i += 1 return count def lilysHomework(arr): return min(countSwaps(arr, False), countSwaps(arr, True))
Seems like cookies are disabled on this browser, please enable them to open this website
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
Python