← General Motors Interview Insights
Use DFS/BFS to explore each island, then normalize its shape by translating coordinates relative to the starting cell and storing the set of relative positions. Count distinct normalized shapes to get the number of distinct islands.
Pro tip: Clarify whether islands are considered distinct based on shape only (translation invariant) or also rotation/reflection; the standard problem assumes translation only, but mentioning this shows attention to detail.
Confirm that distinctness is based on shape (translation invariant) and that movement is only horizontal/vertical. Ask if rotations/reflections count as distinct.
Use DFS or BFS to explore each island. Iterate through the grid; when encountering an unvisited '1', start a traversal to find all connected cells.
During traversal, record each cell's coordinates relative to the starting cell (e.g., subtract the start row and col). Store these relative coordinates in a set or list.
Add the normalized shape (e.g., as a sorted tuple of coordinates) to a global set. After processing all islands, the set size is the number of distinct islands.
Discuss time O(R*C) and space O(R*C) for visited and shape storage. Mention edge cases like empty grid, all water, or all land.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.