Number of Swaps to Sort
Given an array and a sorting algorithm, the sorting algorithm will do a selection swap. Find the number of swaps to sort the array.
Sample input:
[5,4,1,2] -> pair (5,4) -> [4,5,1,2] -> pair (4,1) -> [1,5,4,2] -> pair(5,4) -> [1,4,5,2] -> pair(4,2) -> [1,2,5,4] -> pair(5,4) -> [1,2,4,5].
I was able to solve 9/14 test cases using O^2 time complexity. I first thought it was to figure out the min num of swaps to do it then realized it was different. Ran out of time trying to solve the correct problem.
Sample output:
Return 5
Robot Bounded In Circle
I did something similar to the leetcode answer by checking if it ended up in the same location as start or was not facing north.
I got more than half the test cases on the first and all passed on the second and moved onto the onsite.