Maximum of Minimums for Every Window Size
For every window size 1..n, find the maximum over all windows of that size of the window's minimum.
Open on GeeksforGeeks ↗Intuition
Flip the question per element: for how large a window is a[i] the minimum? Exactly the stretch between its previous-smaller and next-smaller neighbours. Each element then bids for that window size; propagate bids down to smaller sizes.
Approach
Previous & next smaller via stacks
Two monotonic-stack passes give, for each i, the nearest smaller element on each side — the window where a[i] rules as minimum has length len = next[i] − prev[i] − 1.
Bid on the answer array
ans[len] = max(ans[len], a[i]): the best minimum achievable for that exact window length.
Fill gaps right-to-left
A great minimum for length L also works for any shorter window inside it, so ans[k] = max(ans[k], ans[k+1]) sweeping down.
Solution & live demo
Edge cases
Each element's window runs to the right edge; the sweep fills every size correctly.
Use strict inequality on one side only to avoid double-counting equal spans.