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.
intminimumSwaps(intarr_count,int*arr){intindex=0;intswaps=0;intelem=0;inttmp=0;while(true){elem=arr[index];if(elem!=index+1){tmp=arr[index];arr[index]=arr[elem-1];arr[elem-1]=tmp;swaps++;}if(index+1==arr[index]){// move on to the next elementindex++;}if(arr_count==index+1){// we are donebreak;}}returnswaps;}
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 though might be helpfull to someone..