• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 30, 2023 |420 Views
SDE Sheet - Find the number of islands
  Share   Like
Description
Discussion

This video is part of Graphs section under GFG SDE Sheet.

In this video, we are given a grid of size n*m (n is the number of rows and m is the number of columns in the grid) consisting of '0's (Water) and '1's(Land). Find the number of islands.

Note: An island is either surrounded by water or boundary of grid and is formed by connecting adjacent lands horizontally or vertically or diagonally i.e., in all 8 directions.

Example :

Input:
grid = {{0,1},{1,0},{1,1},{1,0}}

Output:
1

Explanation:
The grid is-
0 1
1 0
1 1
1 0
All lands are connected.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-

Article: https://www.geeksforgeeks.org/find-the-number-of-islands-using-dfs/
Problem:  https://practice.geeksforgeeks.org/problems/find-the-number-of-islands/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

 

Read More