Last active
January 12, 2020 12:00
-
-
Save dovideh/deb3d957099e6d928c283d85e8375ab7 to your computer and use it in GitHub Desktop.
min_swp2
This file contains 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): | |
swp = 0 | |
n = len(arr) | |
for i,j in enumerate(arr): | |
if(j != i+1): | |
source_idx = arr.index(i+1) | |
destination_idx = arr.index(j) | |
swp += 1 | |
arr[destination_idx], arr[source_idx] = arr[source_idx], arr[destination_idx] | |
return swp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment