As reported: Coupang USA Staff loop (2025), onsite coding round 2, second question with 15 minutes left: given a 0/1 grid, count the number of distinct shapes.
This is LeetCode 694 — Number of Distinct Islands.
You are given an m × n binary grid. An island is a group of 1s connected 4-directionally. Two islands have the same shape if one can be translated (moved up, down, left or right — not rotated or reflected) to match the other exactly. Return the number of distinct shapes.
Example 1
grid = [[1,0,0,0,1,1],
[1,1,0,0,0,1],
[0,0,0,0,1,0],
[0,0,0,0,1,1]] -> 2
An L shape (top left, and again bottom right) and an inverted L (top right).
Example 2
grid = [[1,1,0,0,0],
[1,1,0,0,0],
[0,0,0,1,1],
[0,0,0,1,1]] -> 1
Example 3
grid = [[1,1,0,1,1],
[1,0,0,0,0],
[0,0,0,0,1],
[1,1,0,1,1]] -> 3
Constraints: 1 ≤ m, n ≤ 50; grid[i][j] is 0 or 1.
Code runner format: one line holding grid (LeetCode's test-case format). Implement numDistinctIslands(grid); the harness prints the count.