AlmostSorted complete solution