Skip to content

added number of islands dsa problem#249

Open
agarwalmonika wants to merge 1 commit into
Nikhil-2002:mainfrom
agarwalmonika:add-number-of-islands-dsa
Open

added number of islands dsa problem#249
agarwalmonika wants to merge 1 commit into
Nikhil-2002:mainfrom
agarwalmonika:add-number-of-islands-dsa

Conversation

@agarwalmonika
Copy link
Copy Markdown

This PR adds a C++ solution for the LeetCode Problem 200 – Number of Islands.

Description:
The problem is to count the number of islands in a 2D grid of '1's (land) and '0's (water).
An island is formed by connecting adjacent lands horizontally or vertically.

Approach:

Used Depth-First Search (DFS) to explore connected land cells.

Each time a new land cell is found, DFS marks all its connected cells as visited.

The total count of DFS calls gives the number of islands.

Complexity:

Time: O(M × N) — each cell is visited once.

Space: O(M × N) — recursion stack in the worst case.

Language: C++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant