heights: the heights of points along a route, in order. You want the route to be **strictly increasing**, and you may achieve that by cutting out one non-empty contiguous block (subarray). The remaining elements close up in their original order; an empty route also counts as strictly increasing.
How many subarrays can you remove so that heights becomes strictly increasing?
The array can be long, so trying every subarray will be too slow.heights=[2, 5, 3, 6] → 8
Eight blocks work: [5], [3], [5, 3], [2, 5], [3, 6], [2, 5, 3], [5, 3, 6] and the whole array. Removing [5], for instance, leaves 2, 3, 6, and removing [3, 6] leaves 2, 5. Cutting out just [2] fails: 5, 3, 6 remains.
heights=[4, 4] → 3
You can remove either 4 or both of them; each time what remains (one element or nothing) is strictly increasing.
heights=[1, 2, 3] → 6
heights=[2, 5, 3, 6]
8
Run checks the first 3 tests in your browser. Submit checks all 155 tests on the server, hidden ones included.