Question bank › Graphs Dfs
Dsa Graphs Dfs Medium

Lakes and Rivers

You are given a 2D grid representing a landscape where '1' represents land and '0' represents water. A lake is defined as a cluster of water (0s) surrounded entirely by land (1s). Your task is to find the total number of lakes (clusters of 0s) in this grid. Input Format: - The first line contains two integers, m and n, where m is the number of rows and n is the number of columns in the grid. - The next m lines contains n characters, either '0' or '1'. Output Format: - Print a single integer representing the total number of lakes. Example: Input: 4 5 11111 11001 11000 11111 Output: 2

Key concepts

graphsdfsgrid traversal

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.