Dsa
Monotonic Stack
Medium
Container Height Comparison
You manage a warehouse with containers of varying heights. Given an array of integers where each integer represents the height of a container, determine the number of taller containers that can be seen from each container. A container can see a taller container if it is to its right and taller than the current container.
If there are no taller containers, output 0.
Write a program that reads an integer n (the number of containers) followed by n integers representing the heights of each container. Print a single line with n integers representing the number of taller containers visible from each container's position.
Input format:
- The first line contains a single integer n (1 <= n <= 100000).
- The second line contains n space-separated integers, where each integer is between 1 and 10000 (inclusive).
Output format:
- A single line with n space-separated integers, the counts of taller containers visible.
Example:
Input:
5
1 2 3 4 5
Output:
0 0 0 0 0
Key concepts
monotonic_stackcontainerheight
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