200. Number of Islands

Practice Number of Islands for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

The grid is a map where "1" is land and "0" is water. An island is a group of land cells connected up, down, left or right (not diagonally). Everything outside the grid is water. Count the islands.

Example

grid = [["1","1","0","0","0"],
        ["1","1","0","0","0"],
        ["0","0","1","0","0"],
        ["0","0","0","1","1"]]  ->  3

Constraints