Question bank › Monotonic Stack
Dsa Monotonic Stack Hard

Relative Height Comparison

You have a series of heights of various objects arranged side by side. For each object's height, you need to find the nearest object (to its left) that is taller. If there isn't one, return -1 for that object. Print the results in a single line. Example: Input: 3 5 2 4 1 Output: -1 -1 1 -1 -1 Input format: A single line containing space-separated integers representing heights. Output format: A single line containing space-separated integers for the nearest taller object’s index to the left.

Key concepts

monotonic_stackheights

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.