Dsa
Monotonic Stack
Medium
Building Shadow Heights
You're given a list of building heights. For each building, you need to calculate how many buildings to the left are shorter than the current one until you hit a taller building or the edge.
Input Format:
- A single line with N (1 <= N <= 100,000) followed by N integers representing the building heights.
Output Format:
- A single line with N integers representing the count of shorter buildings to the left for each building.
Example:
Input:
5 3 1 4 5 2
Output:
0 0 1 2 1
Key concepts
monotonic_stackbuildingsheights
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