Skip to content

Instantly share code, notes, and snippets.

@dovideh
Last active January 12, 2020 12:00
Show Gist options
  • Save dovideh/deb3d957099e6d928c283d85e8375ab7 to your computer and use it in GitHub Desktop.
Save dovideh/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