Dsa
Monotonic Stack
Medium
Building Shadows
You are given a list of building heights. For each building, compute how much sunlight it receives based on the buildings to its left. A building receives sunlight if it's taller than any building to its left. Output a list with 1 if it receives sunlight and 0 otherwise.
Example Input:
5
3 1 4 1 5
Example Output:
1 0 1 0 1
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 30000), the number of buildings.
- The second line contains n space-separated integers, representing the heights of buildings.
Output Format:
- A single line of n integers where each integer is either 1 (receives sunlight) or 0 (no sunlight).
Key concepts
monotonic_stackarraygeometry
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