Dsa
Monotonic Stack
Hard
Rainwater Collection
Given an array of integers representing the heights of bars in a histogram, calculate how much water can be trapped after raining. The water trapped at each bar is determined by the height of the tallest bars to its left and right. You need to output a single integer representing the total units of water trapped.
Example:
Input:
5
0 1 0 2 1
Output:
1
Key concepts
monotonic_stackarraywater_trapping
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