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.
importmathimportosimportrandomimportreimportsys# Complete the minimumSwaps function below.defminimumSwaps(arr):ans=0i=0whilei<len(arr):p=arr[i]ifp<i+1:temp=arr[p-1]arr[p-1]=parr[i]=tempans+=1else:i+=1returnansif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input())arr=list(map(int,input().rstrip().split()))res=minimumSwaps(arr)fptr.write(str(res)+'\n')fptr.close()
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 →