Dsa
Two Pointers
Easy
Water Trapping
Given an array representing the height of bars in a bar graph, write a function to calculate how much water can be trapped between the bars after a rainfall.
Input Format:
- A single line containing space-separated integers, representing the heights.
Output Format:
- An integer representing the total units of water trapped.
Example:
Input:
0 1 0 2 1 0 1 3 2 1 2 1
Output:
6
Key concepts
two_pointersarrayprefix_sum
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