Question bank › Union Find
Dsa Union Find Easy

Island Counts

You are given a grid representing a map of water and land. Your task is to count the number of islands on the map, where an island is formed by connecting adjacent land cells (1s). A water cell is represented by 0. Each cell in the grid can be indexed with (i, j). Input format: - The first line contains two integers R and C (1 ≤ R, C ≤ 1000), the number of rows and columns in the grid respectively. - The next R lines each contain C space-separated integers representing the grid, where 1 indicates land and 0 indicates water. Output format: - Print a single integer representing the number of islands. Example: Input: 3 3 1 0 0 0 1 1 1 0 1 Output: 3

Key concepts

union_findislands

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.