You are viewing a single comment's thread. Return to all comments →
Hey folks, Here is my solution in Ruby, anyone has tips to improve?
def minimumSwaps(arr) changes = 0 index = 0 while index < arr.size item = arr[index] position = index + 1 if item != position arr[index], arr[item - 1] = arr[item - 1], arr[index] changes += 1 else index += 1 end end changes end
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 →
Hey folks, Here is my solution in Ruby, anyone has tips to improve?