Count Island Shapes up to Translation Only

Quick Overview

Count Island Shapes up to Translation Only. Land cells equal one and connect only through shared edges.

Count Island Shapes up to Translation Only

Company: Anduril

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Land cells equal one and connect only through shared edges. Two islands have the same shape exactly when translating one set of cells makes it equal the other; rotations and reflections do not count as equivalent. Return the number of distinct island shapes. ```cpp class Solution { public: int numDistinctIslands(vector<vector<int>>& grid); }; ``` ### Examples **Example 1:** ```text grid = [[1,1,0,1,1],[1,0,0,1,0]] Output: 1 Explanation: The two L shapes differ only by translation. ``` **Example 2:** ```text grid = [[1,1,0,0],[0,0,0,1],[0,0,0,1]] Output: 2 Explanation: Horizontal and vertical two-cell islands are rotations, not translations. ``` ### Constraints - The binary grid has m rows and n columns, each dimension in 1..50; every row contains n entries. ### Clarifying Questions Normalize translation without normalizing rotation or reflection, and keep four-direction connectivity. ```hint Read the boundary condition What coordinate offset cancels an island's absolute location while keeping its orientation? ``` ### Contract considerations Normalize translation without normalizing rotation or reflection, and keep four-direction connectivity.

Overview: Count Island Shapes up to Translation Only. Land cells equal one and connect only through shared edges.

Anduril logo
Anduril
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
1
0

Problem

Land cells equal one and connect only through shared edges. Two islands have the same shape exactly when translating one set of cells makes it equal the other; rotations and reflections do not count as equivalent. Return the number of distinct island shapes.

class Solution {
public:
    int numDistinctIslands(vector<vector<int>>& grid);
};

Examples

Example 1:

grid = [[1,1,0,1,1],[1,0,0,1,0]]
Output: 1
Explanation: The two L shapes differ only by translation.

Example 2:

grid = [[1,1,0,0],[0,0,0,1],[0,0,0,1]]
Output: 2
Explanation: Horizontal and vertical two-cell islands are rotations, not translations.

Constraints

  • The binary grid has m rows and n columns, each dimension in 1..50; every row contains n entries.

Clarifying Questions Guidance

Normalize translation without normalizing rotation or reflection, and keep four-direction connectivity.

Contract considerations

Normalize translation without normalizing rotation or reflection, and keep four-direction connectivity.