Min max riddle – formal proof?

There’s the challenge at Hackerrank: `

Given an integer array of size N, find the maximum of the minimum(s) of every window size in the array. The window size varies from 1 to N.

For example, given [6,3,5,1,12], consider window sizes of 1 through 5. Windows of size 1 are (6) (3) (5) (1) (12). The maximum value of the minimum values of these windows is 12 . Windows of size 2 are (6,3) (3,5) (5,1) (1,12) and their minima are (3) (3) (1) (1). The maximum of these values is 3 . Continue this process through window size to finally consider the entire array. All of the answers are [12,3,3,1,1].

The solution proposed in the editorial and discussions uses stacks, and for me it’s not clear why that works. I can’t work it out using induction neither I can see why that stack would contain the sizes of interest for the minimums across the windows of increasing sizes.

Can somebody please explain the proof of correctness in this case?