← Bytedance Interview Insights

Bytedance·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Bytedance coding round, one algorithmic problem on grid islands. Pretty focused session, just the one question but it had enough depth to keep me busy for a while.

Questions Asked (1)

Q1

Given a binary grid where 1s represent land and 0s represent water, count the number of distinct islands, where two islands are considered identical if one can be translated (but not rotated or reflected) to match the other.

Algorithms & Data Structures
Author's notes

The basic island count with BFS/DFS I can do in my sleep, but the 'distinct' part tripped me up for a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use DFS/BFS to find each island, then normalize its shape by translating it to a canonical form (e.g., relative coordinates from the top-left cell). Store these normalized shapes in a set to count distinct islands.

Pro tip: Emphasize that translation invariance is achieved by using relative coordinates, and mention that the order of traversal doesn't matter as long as the normalization is consistent.

1. Traverse the grid

Iterate through each cell; when encountering unvisited land (1), start a DFS/BFS to explore the entire island.

2. Collect island coordinates

During traversal, record the absolute coordinates of all cells belonging to the island.

3. Normalize the shape

Translate the island to a canonical form by subtracting the minimum row and column from all coordinates, making it invariant to translation.

4. Store and count distinct shapes

Insert the normalized shape (e.g., as a sorted list of coordinates or a string) into a set; the set size gives the number of distinct islands.

Key Points to Mention

  • DFS/BFS for island exploration
  • Translation invariance via relative coordinates
  • Using a set to deduplicate shapes
  • Time and space complexity analysis (O(R*C) time, O(R*C) space)
  • Handling of edge cases (empty grid, no islands)
  • Comparison with similar problems (e.g., number of islands, distinct islands with rotations/reflections)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.