Number of Islands
Asked in the Round 1 technical stage. Explained BFS and DFS with complexity.
Given a rectangular grid containing "1" for land and "0" for water, return the number of islands. An island is a group of horizontally or vertically adjacent land cells.
Implement num_islands(grid) and return an integer. Do not count diagonal adjacency. The input may be empty.
def num_islands(grid):