Find the Minimum Cost Array Permutation
Arrange the indices in a closed cycle. Each step between neighbours costs the gap between the current value and the value stored at the next index. Find the cheapest cycle, breaking ties toward the smallest arrangement.