readings. You want the series to never decrease, and you are allowed exactly one operation: remove **one contiguous block** (it may be empty). The remaining values are joined together in their original order.
Return the smallest block length whose removal leaves a non-decreasing series (each value no smaller than the one before it).readings=[2, 4, 9, 1, 3, 5, 6] → 3
Cut out [9, 1, 3] and [2, 4, 5, 6] remains, which never decreases. Removing only two values is not enough.
readings=[7, 6, 5] → 2
The values only go down, so only one of them can stay: two must go.
readings=[1, 1, 3, 8] → 0
The series already never decreases, so nothing has to be cut.
readings=[2, 4, 9, 1, 3, 5, 6]
3
Run checks the first 3 tests in your browser. Submit checks all 192 tests on the server, hidden ones included.