← Bytedance Interview Insights
The basic translation-only version I had down cold.
First, traverse the grid to identify each island using DFS/BFS, recording its cells. For each island, normalize its shape by generating all 8 symmetries (rotations and reflections) and translating each to a canonical form (e.g., min row and col at 0). Use a hash set to count distinct normalized shapes.
Pro tip: When normalizing, ensure you consider all 8 transformations and pick a canonical representation that is invariant under translation, rotation, and reflection. Also, handle edge cases like single-cell islands and large grids efficiently by using a set of tuples for shape signatures.
Use DFS or BFS to find all connected components of land cells (1s) in the grid, collecting the coordinates of each island.
For each island, generate all 8 possible transformations (4 rotations × 2 reflections) and translate each so that the minimum row and column are 0. Convert each transformed shape to a canonical tuple representation.
Among all transformed versions of an island, choose the lexicographically smallest tuple as the canonical signature for that island.
Insert each island's canonical signature into a hash set. The number of distinct shapes is the size of the set.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.