Skip to content

Instantly share code, notes, and snippets.

@ovidiucs
Last active January 12, 2020 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovidiucs/deb3d957099e6d928c283d85e8375ab7 to your computer and use it in GitHub Desktop.
Save ovidiucs/deb3d957099e6d928c283d85e8375ab7 to your computer and use it in GitHub Desktop.
min_swp2
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