3. What is the output of the following Go code that counts islands using BFS on this grid?
grid := [][]byte{
{'1','1','0','0','0'},
{'1','1','0','0','0'},
{'0','0','1','0','0'},
{'0','0','0','1','1'},
}
count := numIslands(grid)
fmt.Println(count)
func numIslands(grid [][]byte) int {
rows, cols := len(grid), len(grid[0])
count := 0
directions := [][]int{{1,0},{-1,0},{0,1},{0,-1}}
for i := 0; i < rows; i++ {
for j := 0; j < cols; j++ {
if grid[i][j] == '1' {
count++
queue := [][]int{{i,j}}
grid[i][j] = '0'
for len(queue) > 0 {
r, c := queue[0][0], queue[0][1]
queue = queue[1:]
for _, d := range directions {
nr, nc := r+d[0], c+d[1]
if nr >= 0 && nr < rows && nc >= 0 && nc < cols && grid[nr][nc] == '1' {
queue = append(queue, []int{nr,nc})
grid[nr][nc] = '0'
}
}
}
}
}
}
return count
}