You are viewing a single comment's thread. Return to all comments →
def minimumSwaps(arr): visited = [False for x in range(len(arr))] total_count_swap = 0 for i in range(len(arr)): if (visited[i]): continue count_swap = 0 cur = i+1 while (not visited[cur-1]): visited[cur-1] = True cur = arr.index(cur) + 1 count_swap += 1 total_count_swap += count_swap - 1 return total_count_swap
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →