Given a 2D grid of 1s (land) and 0s (water), count the number of islands using a BFS-based flood fill. An island is a maximal group of 1s connected horizontally or vertically. The input is JSON {grid}.
Input: JSON {grid}.
Output: Integer — the number of islands.
Input: {"grid":[[1,1,0,0],[1,0,0,1],[0,0,1,1]]}
Output: 2
Explanation: Two land masses.Input: {"grid":[[0]]}
Output: 0
Explanation: All water.Input: {"grid":[[1,0,1]]}
Output: 2
Explanation: Two separate cells.1<=rows,cols<=300cells are 0 or 1