You are viewing a single comment's thread. Return to all comments →
Since you go from i=0 to n-1, you don't need to set values to previous 'i', so deleting these two lines will make sense:
arr[index] = arr[swappingIndex];
and
indexDict[index + 1] = index;
Also, you don't need to check the last value, so it should iterate to: index < arr.Length - 1;
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 →
Since you go from i=0 to n-1, you don't need to set values to previous 'i', so deleting these two lines will make sense:
arr[index] = arr[swappingIndex];
and
indexDict[index + 1] = index;
Also, you don't need to check the last value, so it should iterate to: index < arr.Length - 1;