Dsa
Monotonic Stack
Easy
The Lighthouse Sightline
You are observing a row of lighthouses of various heights. Each lighthouse emits a horizontal beam of light to the right. A beam continues until it hits a lighthouse that is strictly taller than the originating one. For each lighthouse, determine the 0-indexed position of the lighthouse that stops its beam. If the beam never hits a taller lighthouse, output -1.
Input Format: A single line containing space-separated integers representing lighthouse heights.
Output Format: A single line containing space-separated integers representing the stopping indices.
Example:
Input: 4 2 5 3
Output: 2 2 -1 -1
Key concepts
monotonic_stacknext_greater_element
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