Number of Islands
Asked in the Round 2 - DSA stage. Given a 2D grid of "1" values representing land and "0" values representing water, return the number of islands. An island is formed by horizontally or vertically adjacent land cells, and each island must be surrounded by water or the grid boundary.
Implement num_islands(grid). The input is a list of lists of strings. Return an integer count. Mark visited land cells so they are not counted again.
def num_islands(grid):