Write a function to calculate the number of islands in a 2D grid where 1 represents land and 0 represents water.
HardProblem Statement
Write a function to calculate the number of islands in a 2D grid where 1 represents land and 0 represents water.
Sample Input
[ [1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 1] ]
Sample Output
Number of Islands: 3
Limits
Time: 2s · Memory: 256 MB