Question bank › Monotonic Stack
Dsa Monotonic Stack Medium

Building Ground View

A city skyline is formed by a sequence of buildings of varying heights. Given the heights of these buildings, your task is to calculate the length of the silhouette as viewed from a perspective of the ground. When buildings overlap in height, you should count the length of unbroken silhouette. Write a function to read the heights of buildings and output the length of the skyline. Input format: - The first line contains an integer n (1 <= n <= 100000), the number of buildings. - The second line contains n space-separated integers representing the heights of the buildings. Output format: - Print a single integer representing the total skyline length. Example: Input: 5 3 1 4 1 5 Output: 8

Key concepts

monotonic_stackbuildingsskyline

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.