Question bank › Monotonic Stack
Dsa Monotonic Stack Hard

Rainfall Calculation

Given an array of integers representing the height of elevation in a landscape, calculate how much rain can be trapped after raining. Assume that the bounds are infinite on both sides. Input format: - A single line of space-separated integers representing the heights of the landscape (0 <= heights[i] <= 10000). Output format: - A single integer representing the total units of rainwater trapped. Example: Input: 0 1 0 2 1 0 1 3 2 1 2 1 Output: 6

Key concepts

monotonic_stackwater_trappingmatrix

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.