Search⌘ K
AI Features

Solution: Number of Distinct Islands

Explore the solution to find the number of distinct islands in a binary matrix by using a depth-first search approach combined with hash maps. Understand how to identify unique island shapes through coordinate normalization and track them effectively to solve the problem within optimal time and space complexity.

Statement

Given an m x n binary matrix where 11 represents land and 00 represents water. An island is a group of connected 1s1s that are adjacent horizontally or vertically. Two islands are considered the same if one matches the other without rotating or flipping. The task is to return the number of distinct islands.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 11 \leq m, n ...