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.
Hi Samuel,
Iterate though the array from the beginning (presumably sequence starts from 1) and find the element in a wrong place.
So if
arr[i] != i+1
for example
arr[1] = 3
this means the second element in the array with the value of 3 should be in the third place
arr[2] = 3.
Put the element in his place
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
Hi Samuel, Iterate though the array from the beginning (presumably sequence starts from 1) and find the element in a wrong place. So if arr[i] != i+1 for example arr[1] = 3 this means the second element in the array with the value of 3 should be in the third place arr[2] = 3. Put the element in his place
Keep iterating finding and placing the element in the correct position until all of those are in place
while (first < last)