Dsa
Monotonic Stack
Easy
The Valley Floor
A series of ground elevations forms a landscape. For each point $i$, we want to find the width of the largest 'Valley' containing $i$ where the elevation at $i$ is the minimum. Specifically, find the number of contiguous points $[L, R]$ such that for all $k \in [L, R]$, $elevation[k] \ge elevation[i]$.
Input Format: A single line of space-separated integers.
Output Format: A single line of space-separated integers representing the width of the valley for each point.
Example:
Input: 3 1 4 2
Output: 1 4 1 2
Key concepts
monotonic_stackrange_width
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now