Number of distinct islands

Write codeHard35 min

Your task

Given an m x n binary grid, an island is a group of 1s connected 4-directionally. Two islands are considered the same if and only if one can be translated (shifted, not rotated or reflected) to equal the other. Return the number of distinct island shapes. The grid may be empty of land.

Examples

num_distinct_islands(grid: list[list[int]]) -> int
Example 1
Inputnum_distinct_islands([[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 0, 1, 1], [0, 0, 0, 1, 1]])
Output1