A sequential unique list of numbers (1,2,3,...,n) has been randomized and I need to sort it by moving one item at a time to the end of the list. Which algorithm will provide th
Here's an algorithm:
Quite intuitive, just think about it. Example:
12345 -> 25341
|25| is in increasing order and after that it becomes decreasing.
Length (2,5) = 2
Answer = 5 - 2 = 3
If your list isn't sorted in increasing order, you could always map it via indices.