Created
January 30, 2020 20:50
-
-
Save rasel-rz/3c03575f4a606aa1c5f3a1ca219c2ed3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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