0

Python

Write a function count_islands(grid) that takes a 2D list representing a map of '1's (land) and '0's (water) and returns the number of distinct islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically (not diagonally). Use recursion (DFS) for the solution.

21st Apr 2025, 6:42 AM
InfiniteSearch
InfiniteSearch - avatar
3 Antworten
+ 5
Go ahead, complete the task, we're here to help. Btw, it's required to post specific and relevant questions in Discuss section, and it's the most observed section. So check these threads out for info: https://www.sololearn.com/Discuss/1316935/?ref=app https://www.sololearn.com/Discuss/333866/?ref=app https://www.sololearn.com/Discuss/3021159/?ref=app
21st Apr 2025, 2:47 PM
Shihan
Shihan - avatar
+ 4
Is this a test? Ready made codes are not available in the forums. This is a popular coding challenge so post your attempt and others may try to help you 😉
21st Apr 2025, 5:42 PM
Keith
Keith - avatar
+ 2
Yes, write it. If you face any problems or need help about what you need to do, tell us with your code and we'll help.
21st Apr 2025, 7:15 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar