Question bank › Graphs Dfs
Dsa Graphs Dfs Medium

Island Counting

You are given a 2D grid of '0's (water) and '1's (land). An island is formed by connecting adjacent lands horizontally or vertically. Write a program to count the number of distinct islands in the grid. Input Format: - The first line contains two integers, M (rows) and N (columns). - The next M lines each contain a string of length N representing the grid. Output Format: - Print a single integer indicating the number of distinct islands. Example: Input: 4 5 11000 11000 00100 00011 Output: 3

Key concepts

graphsdfsislands

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