heights[i] is the height of stone i. A route is a set of stones taken from left to right (not necessarily adjacent) where every next stone is at least as high as the one before it.
For every index i, find the length of the longest route that ends exactly on stone i (it includes that stone and uses only stones with indices 0 to i).
Return the array of these lengths.heights=[4, 2, 4, 3, 5, 1] → [1, 1, 2, 2, 3, 1]
For the stone of height 5 (index 4) the route 2 → 3 → 5 or 2 → 4 → 5 works: three stones. The last stone, of height 1, is lower than everything before it, so its route is just itself.
heights=[6, 6, 2, 6] → [1, 2, 1, 3]
Equal heights may follow each other: the route 6 → 6 → 6 of length 3 reaches the last stone.
heights=[4, 2, 4, 3, 5, 1]
[1, 1, 2, 2, 3, 1]
Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.