← LinkedIn Interview Insights

LinkedIn·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

LinkedIn SWE coding round, pretty much what you'd expect. One algorithmic problem, classic grid traversal stuff.

Questions Asked (1)

Q1

Given a 2D binary grid where 1s represent land and 0s represent water, count the number of distinct islands. Islands are formed by horizontally or vertically connected land cells.

Algorithms & Data Structures
Author's notes

Classic flood-fill problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a graph traversal algorithm (DFS or BFS) to explore each unvisited land cell, marking all connected land cells as visited to count one island. Iterate through the grid, and for each unvisited '1', increment the island count and perform a traversal to mark the entire island.

Pro tip: Discuss the trade-offs between DFS and BFS, especially regarding stack overflow risks with DFS on large grids, and mention that you can modify the grid in-place to save space if allowed. Also, clarify assumptions about grid boundaries and connectivity (4-directional vs 8-directional).

1. Clarify the problem

Confirm the definition of an island (4-directional connectivity), input constraints (grid size, mutability), and expected output (integer count).

2. Choose traversal method

Decide between DFS (recursive or iterative) and BFS, considering space complexity and potential stack overflow. Explain your choice.

3. Implement traversal and marking

Write a function that, given a starting cell, explores all connected land cells and marks them as visited (e.g., set to '0' or use a visited set).

4. Iterate and count

Loop through each cell in the grid; when an unvisited '1' is found, increment the island count and trigger the traversal to mark the entire island.

5. Analyze complexity

State time complexity O(M*N) and space complexity O(M*N) in worst case (e.g., all land), and discuss optimizations if needed.

Key Points to Mention

  • Time and space complexity analysis
  • DFS vs BFS trade-offs (recursion depth vs queue memory)
  • In-place modification vs separate visited set
  • Handling edge cases (empty grid, single cell, all water)
  • Connectivity definition (4-directional vs 8-directional)
  • Potential for iterative DFS to avoid stack overflow

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