Question bank › Monotonic Stack
Dsa Monotonic Stack Hard

Building Sunset

You are given a list of building heights, where the i-th building is of height `h[i]`. A building can see the sunset if all buildings to its right are shorter than it. Compute the indices of the buildings that can view the sunset, from left to right. Input format: - A single line containing integers separated by spaces, representing the heights of the buildings. Output format: - A single line containing integers separated by spaces, representing the 0-based indices of the buildings that can see the sunset. Example: Input: 3 7 8 3 6 1 Output: 1 2

Key concepts

monotonic_stackbuildingview

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.