Back to problems

Count Distinct Island Shapes in a Binary Grid

Algorithm · Two Sigma · Medium

Suppose you are given a binary matrix grid with m rows and n columns. Each cell contains either 0 (water) or 1 (land). An island is a maximal component of land cells connected by horizontal or vertical adjacency. Diagonal adjacency does not join cells. Two islands have the same shape if and only if there exist integer offsets dr and dc such that adding (dr, dc) to every cell of one island yields exactly the set of cells of the other island. Rotating or reflecting an island…

Checking your access…