Dsa
Monotonic Stack
Easy
Water Trapping Calculation
Given an array of non-negative integers representing the height of bars in a histogram, calculate how much water can be trapped between the bars after it rains. The trapped water at any index is determined by the height of the tallest bars to the left and right of it.
Input Format:
- A single line of space-separated integers representing the heights of the bars.
Output Format:
- A single integer representing the total amount of trapped water.
Example:
Input:
1 0 2 1 0 1 3 2 1 2 1
Output:
6
Key concepts
monotonic_stackwater_trappingarrays
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