Problem 1063 · Hard

Number of Valid Subarrays

Count subarrays whose first value is no larger than every later value in that subarray. A monotonic stack shows how far each value can extend to the right.

Open the interactive visualisation