You are viewing a single comment's thread. Return to all comments →
More clear version of your code:
def minimumSwaps(arr): temp = {a: i for i, a in enumerate(arr)} swaps = 0 for i in range(len(arr)): actual, expected = arr[i], i + 1 actual_i, expected_i = i, temp[expected] if actual != expected: arr[actual_i] = expected arr[expected_i] = actual temp[actual] = expected_i temp[expected] = actual_i swaps += 1 return swaps
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
More clear version of your code: