heights of length n. For each width w from 1 to n, look at every contiguous stretch of the array with length w, take the minimum of each, and pick the largest of those minimums.
Return an array of length n whose entry at index w - 1 is the answer for width w.
The direct approach is O(n²); try to get it down to O(n).heights=[3, 1, 4, 2] → [4, 2, 1, 1]
Width 1: the best minimum is 4. Width 2: windows [3,1], [1,4], [4,2] give 1, 1, 2, so the best is 2. Widths 3 and 4: every window contains the 1.
heights=[5, 6, 6, 5] → [6, 6, 5, 5]
The window [6, 6] gives a minimum of 6 at width 2; at width 3 every window already contains a 5.
heights=[3, 1, 4, 2]
[4, 2, 1, 1]
Run checks the first 3 tests in your browser. Submit checks all 142 tests on the server, hidden ones included.