← LinkedIn Interview Insights

LinkedIn·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

LinkedIn software engineer interview with a classic grid traversal problem. Nothing too surprising but it's the kind of question where you either see it immediately or you spend five minutes staring at the grid like it owes you money.

Questions Asked (1)

Q1

Given a 2D grid of '1's (land) and '0's (water), count the number of islands, where an island is a group of land cells connected horizontally or vertically.

Algorithms & Data Structures
Author's notes

Classic BFS/DFS flood fill.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Treat the grid as a graph and use DFS or BFS to explore each unvisited land cell, marking all connected land as visited to count one island. Iterate through every cell, incrementing the island count each time you start a traversal from an unvisited '1'.

Pro tip: Mention that you can mutate the input grid to mark visited cells (e.g., set to '0') to save space, but clarify that if the input must be preserved, use a separate visited set. This shows awareness of trade-offs and real-world constraints.

1. Clarify and Confirm

Restate the problem to ensure understanding: count connected components of '1's using 4-directional adjacency. Ask about edge cases like empty grid, large input, or if diagonal connections count.

2. Choose Traversal Method

Decide between DFS (recursive or iterative) and BFS. Discuss trade-offs: DFS is simpler but may cause stack overflow on large grids; BFS uses a queue and avoids recursion depth issues.

3. Design Algorithm

Iterate through each cell. When a '1' is found, increment island count and perform DFS/BFS to mark all connected '1's as visited (e.g., set to '0' or use a visited matrix).

4. Analyze Complexity

State time complexity O(M×N) since each cell is visited once, and space complexity O(M×N) in worst case for recursion stack or queue.

5. Test and Optimize

Walk through a small example, consider edge cases (all water, all land, single row/column). Mention possible optimizations like union-find for dynamic scenarios.

Key Points to Mention

  • Graph traversal (DFS/BFS) to find connected components
  • In-place modification vs. separate visited set and trade-offs
  • Time and space complexity analysis
  • Handling edge cases (empty grid, no islands, all land)
  • Iterative vs. recursive DFS and stack overflow risk
  • Alternative approach: Union-Find (disjoint set) for dynamic connectivity

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