Back to the Problem
Sweep from the right carrying the minimum, then output left to right.
Complexity: O(N)