Problems > Is This Slice Sorted > Editorial

Is This Slice Sorted — Solution & Editorial

Back to the Problem

Prefix-count the DESCENT positions (ai < ai−1); a slice is sorted iff it contains none strictly inside.

Complexity: O(N + Q)