Algorithm · ByteDance · Medium
Problem: Number of Islands and Island Perimeter You are given an m x n 2D binary grid called grid, where: 1 signifies land; 0 signifies water. Two land cells belong to the same island if they are connected vertically or horizontally (4-directional adjacency). The area outside the grid is treated as water. Your task is to compute two values: The total number of islands in the grid. The perimeter of all islands combined — that is, the count of land edges that touch either…
Checking your access…