← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Pinterest coding interview with a classic grid traversal problem. Nothing too surprising but it still required clean execution under pressure.

Questions Asked (1)

Q1

Given a 2D binary grid representing a map where '1' is land and '0' is water, count the number of islands. An island is a group of adjacent land cells connected horizontally or vertically.

Algorithms & Data Structures
Author's notes

Classic BFS/DFS problem and I knew it immediately, which almost made it worse because I rushed into code without talking through edge cases first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a graph traversal algorithm like BFS or DFS to explore each unvisited land cell and mark all connected land cells as visited, incrementing the island count for each new traversal. Alternatively, use Union-Find to group adjacent land cells and count distinct sets.

Pro tip: Discuss trade-offs between BFS and DFS, especially regarding recursion depth and memory usage, and mention how to handle very large grids by using iterative BFS to avoid stack overflow.

1. Clarify the problem

Confirm the definition of an island, adjacency rules (horizontal/vertical), and grid boundaries. Ask about input size and constraints to choose the right algorithm.

2. Choose an algorithm

Decide between BFS, DFS, or Union-Find based on constraints and personal comfort. Explain why you chose it, considering time and space complexity.

3. Outline the traversal

Describe how you will iterate through each cell, and when you find a '1', increment the count and traverse all connected '1's, marking them as visited (e.g., set to '0' or use a visited matrix).

4. Analyze complexity

State that time complexity is O(M*N) where M and N are grid dimensions, as each cell is visited once. Space complexity is O(M*N) in the worst case for the queue/stack or recursion depth.

5. Test with examples

Walk through a small example to verify correctness, including edge cases like empty grid, all water, all land, and single row/column.

Key Points to Mention

  • Time and space complexity analysis
  • Choice of BFS vs DFS and trade-offs (recursion depth, memory)
  • Handling of visited cells to avoid infinite loops
  • Edge cases: empty grid, no islands, all land, large grid
  • Alternative approach using Union-Find and its complexity
  • In-place modification vs extra space for visited tracking

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