Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The key is to find the longest non-decreasing subarray starting with the first element or ending with the last element, respectively.
After removing some subarray, the result is the concatenation of a sorted prefix and a sorted suffix, where the last element of the prefix is smaller than the first element of the suffix.