Question bank › Monotonic Stack
Dsa Monotonic Stack Medium

Next Greater Element in Skyline

You are given an array of integers representing heights of buildings in a skyline. For each building, find the index of the next taller building to the right. If there isn't one, output -1 for that building. Example input: 6 2 1 5 6 2 3 Example output: 2 4 4 -1 5 -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 representing the index of the next taller building for each building.

Key concepts

monotonic_stackarrayskyline

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.