← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Snapchat software engineer interview with a grid-based algorithm problem. Pretty standard coding round but the problem had a twist that tripped me up a bit.

Questions Asked (1)

Q1

Given a 2D grid of land and water cells, find the maximum perimeter across all islands, where an island is a group of land cells connected horizontally or vertically. Return 0 if there's no land.

Algorithms & Data Structures
Author's notes

My first instinct was to just count edges per cell and sum them up, which is the right direction, but I kept second-guessing myself on whether to use BFS or DFS to group cells per island.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use DFS or BFS to traverse each island, computing its perimeter by counting the four edges of each land cell that are either out of bounds or adjacent to water. Track the maximum perimeter across all islands and return 0 if no land is found.

Pro tip: Clarify edge cases upfront (e.g., empty grid, all water, single cell) and mention that you can compute perimeter during traversal without extra space, showing attention to efficiency.

1. Understand the problem and edge cases

Confirm that islands are connected horizontally/vertically, and that perimeter is the total number of exposed edges. Discuss edge cases like empty grid, no land, and single cell.

2. Choose traversal method

Decide between DFS (recursive or iterative) and BFS. Mention that DFS is often simpler for grid traversal, but be prepared to discuss trade-offs like recursion depth.

3. Compute perimeter during traversal

For each land cell, check its four neighbors. If a neighbor is out of bounds or water, increment the perimeter by 1. Avoid double-counting by marking visited cells.

4. Track maximum perimeter

Maintain a global variable for the maximum perimeter found so far. After traversing each island, update the maximum if the current island's perimeter is larger.

5. Analyze complexity and optimize

State that time complexity is O(m*n) since each cell is visited once, and space complexity is O(m*n) in the worst case for the visited set or recursion stack. Mention potential optimizations like modifying the grid in-place to avoid extra space.

Key Points to Mention

  • Use DFS/BFS to explore each island and mark visited cells to avoid infinite loops.
  • Perimeter calculation: for each land cell, count edges that are out of bounds or adjacent to water.
  • Handle edge cases: empty grid, no land, single land cell, and multiple islands.
  • Time complexity O(m*n) and space complexity O(m*n) due to visited set or recursion stack.
  • In-place modification of the grid (e.g., changing land to water) can reduce space complexity to O(1) if allowed.
  • Return 0 if no land is found, ensuring the initial max perimeter is set to 0.

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