Dsa
Graphs Dfs
Easy
Island Counter
Given a 2D grid of '1's (land) and '0's (water), write a program to count how many distinct islands are present in the grid. Two islands are considered distinct if they are not connected directly (horizontally or vertically). The grid is represented as follows:
Input Format:
- The first line contains two integers, m (number of rows) and n (number of columns).
- The next m lines each contain n characters ('0' or '1').
Output Format:
- Print the number of distinct islands.
Example:
Input:
4 5
11000
11000
00011
00011
Output:
2
Key concepts
graphsdfscounting
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