Question bank › Graphs Bfs
Dsa Graphs Bfs Easy

Island Count in a Grid

You are given a 2D grid representing a map of water and land. '.' represents water and '#' represents land. Write a function that counts the number of distinct islands on the map. An island is formed by connecting adjacent lands horizontally or vertically. Input: The first line contains two integers N and M, the dimensions of the grid. The next N lines each contain M characters '.' or '#'. Output: A single integer representing the number of distinct islands. Example: Input: 4 5 ..... ..#.. ..#.. ..... Output: 1

Key concepts

graphsbfsgrid

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.