Dsa
Monotonic Stack
Hard
Water Tank Filling
You have a water tank that gets filled with water over various days. You are given an array representing the height of the tank on each day. For each day, you want to calculate how much water can be captured between the current day's height and the previous maximum heights.
Input:
A single line containing space-separated integers representing the height of the tank each day.
Output:
A single line containing space-separated integers representing the amount of water captured each day.
Example:
Input:
0 1 0 2 1 0 1 3 2 1 2 1
Output:
0 0 1 0 1 2 1 0 1 0 0 0
Key concepts
monotonic_stackarraytrapping_water
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