You are viewing a single comment's thread. Return to all comments →
I came up with a similar but not exactly the same approach in which i just counted mismatches and thought to apply some function on mismatches that would directly give swaps:
return mismatches//2 + 1
But it somehow fails test case 1, 2, 3, 6.
In the end I decided to go with actually swapping and counting it
Isn't there any such function that could direcly be applied on mismatch count to yield number of swaps?