Back to problems

Number of Islands and Grid BFS Variants

Algorithm · ByteDance · Hard

Requirements Prepare to handle several extensions of the standard grid-island problem: Island counting: Implement numIslands(grid) to return the number of groups of 1 cells connected through the four cardinal directions. Preserving the input: Implement the breadth-first version without changing grid; maintain visited coordinates separately. Matching island shapes: Once the islands are identified, determine how many have an identical shape. Represent each island using…

Checking your access…