We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def minimumSwaps(arr):
counter = 0
for i in range(len(arr)):
if (arr[i]) != i+1:
l = arr.index(i+1)
arr[i],arr[l] = i+1,arr[i]
counter += 1
return counter
Intuitively, this approach ought to be more concise and quicker than creating a separate list, but it actually takes significantly longer! (Tried timing it in another kernel; mine could take up to 3 to 4 times as long as eparas')
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
I tried the following:
Intuitively, this approach ought to be more concise and quicker than creating a separate list, but it actually takes significantly longer! (Tried timing it in another kernel; mine could take up to 3 to 4 times as long as eparas')