heights[0], heights[1], …. The board at index anchor is marked.
Choose a run of consecutive boards from i to j that contains the marked board (i ≤ anchor ≤ j). Its value is the height of its lowest board times the number of boards: min(heights[i..j]) · (j − i + 1).
Return the largest value of such a run.heights=[2, 6, 5, 8, 1], anchor=2 → 15
Boards 1 through 3: the lowest is 5, there are three boards, 5 × 3 = 15. Adding the board of height 2 or 1 drops the height more than the width grows.
heights=[3, 3, 3, 3], anchor=0 → 12
All boards are equal, so take the whole fence: 3 × 4 = 12.
heights=[1, 9, 1], anchor=1 → 9
Board 9 alone gives 9, while with its neighbours it is only 1 × 3 = 3.
heights.length ≤ 10⁵heights[i] ≤ 2 · 10⁴anchor < heights.lengthheights=[2, 6, 5, 8, 1], anchor=2
15
Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.