levels. Call a contiguous stretch of the series *stable* if its first reading is no greater than any other reading in that stretch.
Count the non-empty stable stretches. Stretches with different boundaries count separately even when their values match. A single-element stretch is always stable.
Checking every stretch takes O(n²); aim for something faster.levels=[3, 5, 4, 1] → 6
The valid stretches are [3], [5], [4], [1], [3, 5] and [3, 5, 4]; [5, 4] fails because 4 < 5. That makes 6.
levels=[7, 7] → 3
[7], [7] and [7, 7]: equal values are allowed, so there are 3.
levels=[9, 6, 2] → 3
levels=[3, 5, 4, 1]
6
Run checks the first 3 tests in your browser. Submit checks all 141 tests on the server, hidden ones included.