Dsa
Graphs Bfs
Easy
Water Distribution
You are given a grid representing a system of pipelines to distribute water. A cell with a 0 represents a blocked section, while a cell with a positive integer represents the amount of water that can flow through it. Determine the maximum amount of water that can be collected when flowing from the top-left corner to the bottom-right corner of the grid. You can only move down or right. If it is impossible to reach the target, return 0.
Input format:
R C
0/P1 P2 P3 ...
Where R is the number of rows (1 <= R <= 100) and C is the number of columns (1 <= C <= 100), and each following line contains C integers indicating the pipeline flow.
Output format:
Print the maximum water that can be collected or 0.
Example:
Input:
3 3
1 2 0
0 2 1
1 0 3
Output:
4
Key concepts
graphsbfsflow
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