← Snap Interview InsightsSoftware Engineer

Snap·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Snapchat SWE interview that was basically a grid traversal problem with a twist. Nothing too wild but the follow-up about optimization tripped me up a bit.

Questions Asked (1)

Q1

Given a binary grid with multiple islands, find the maximum perimeter among all islands. Each island is a 4-connected group of land cells, and perimeter counts edges bordering water or the grid boundary.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew LC 463 so the base logic wasn't the problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use BFS or DFS to traverse each island, computing its perimeter by counting water/boundary edges for each land cell. Track the maximum perimeter across all islands, ensuring each cell is visited once.

Pro tip: During traversal, compute perimeter on the fly by checking each neighbor: if it's water or out of bounds, add 1 to the perimeter. This avoids a second pass and keeps the solution efficient.

1. Clarify the problem

Confirm that islands are 4-connected, perimeter counts edges bordering water or grid boundary, and we need the maximum perimeter among all islands.

2. Choose traversal method

Select BFS or DFS to explore each island. BFS is iterative and avoids recursion depth issues; DFS is simpler to code.

3. Traverse and compute perimeter

For each unvisited land cell, start a traversal. For each land cell, check its four neighbors; if a neighbor is water or out of bounds, increment the perimeter.

4. Track maximum perimeter

After finishing an island, compare its perimeter with the current maximum and update if larger.

5. Analyze complexity

Time complexity is O(m*n) since each cell is visited once. Space complexity is O(m*n) for the visited set and queue/stack in the worst case.

Key Points to Mention

  • Use BFS/DFS to explore each island and mark visited cells to avoid revisiting.
  • Compute perimeter by checking each land cell's four neighbors: count edges that are water or out of bounds.
  • Handle edge cases: empty grid, no islands, single cell island, islands touching boundary.
  • Time complexity O(m*n) and space complexity O(m*n) due to visited set and queue/stack.
  • Optimization: modify grid in-place to mark visited cells to save space (if allowed).
  • Alternative: union-find to group islands, but BFS/DFS is simpler and more efficient for this problem.

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