vastly improved algo for AlmostSortedInterval, but math is bad