Question bank › Monotonic Stack
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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.