Dsa
Monotonic Stack
Easy
Apartment View
You are given the heights of apartments in a line. An apartment can see the sunset if there are no taller apartments to its right. Calculate how many apartments can see the sunset.
Input:
- The first line contains an integer n (1 <= n <= 10000), the number of apartments.
- The second line contains n integers denoting the heights of the apartments.
Output:
- A single integer representing the number of apartments that can see the sunset.
Example:
Input:
5
3 7 8 3 6
Output:
3
Key concepts
monotonic_stackapartmentsviews
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