Problem 2832 · Medium

Maximal Range That Each Element Is Maximum in It

Two monotonic-stack passes find the nearest strictly greater value on each side; the gap between them is the range.

Open the interactive visualisation