Practice 1
Practice 1
💡 Task Description:
You are given a 2D grid map representing a map of '1's (land) and '0's (water). Your goal is
to find the number of islands in the grid. An island is surrounded by water and is formed by
connecting adjacent lands horizontally or vertically. You can assume that all four edges of
the grid are surrounded by water.
🧩 Problem Statement:
● The grid is represented as a 2D array of characters, where:
○ '1' represents land.
○ '0' represents water.
● An island is a group of connected '1's (land) cells connected horizontally or
vertically.
● You need to count how many islands are present in the grid.
grid = [
["1", "1", "0", "0", "0"],
["1", "1", "0", "0", "0"],
["0", "0", "1", "0", "0"],
["0", "0", "0", "1", "1"]
]
Expected result
3
You need to solve this problem using both BFS (Breadth-First Search) and DFS
(Depth-First Search) algorithms.
Steps to Follow:
Task Requirements:
📝 Submission:
1. Submit your solution as a single file.
2. The file should include both BFS and DFS implementations.
3. Add sample test cases to verify your solution.