Skip to content

Instantly share code, notes, and snippets.

@rasel-rz
Created January 30, 2020 20:50
Show Gist options
  • Save rasel-rz/3c03575f4a606aa1c5f3a1ca219c2ed3 to your computer and use it in GitHub Desktop.
Save rasel-rz/3c03575f4a606aa1c5f3a1ca219c2ed3 to your computer and use it in GitHub Desktop.
def minimumSwaps(arr):
arr = [x - 1 for x in arr]
i = 0
count = 0
while i < len(arr):
# print(i)
temp = arr[i]
if(i != arr[i]):
arr[i] = arr[temp]
arr[temp] = temp
count += 1
if(arr[i] == i):
i += 1
# print("increment")
else:
i += 1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment