Question bank › Monotonic Stack
Dsa Monotonic Stack Medium

Neighbor Heights

You have a list of building heights representing a skyline. For each building, determine the closest taller building to its left and how far it is. If there is no taller building, return -1 for that position. Input Format: - A single line containing space-separated integers representing the heights of the buildings. Output Format: - A single line containing space-separated integers representing the distance to the closest taller building to the left. Example: Input: 2 1 3 2 5 Output: -1 1 1 2 1

Key concepts

monotonic_stackneighbor_analysisbuilding_heights

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