← LinkedIn Interview Insights

LinkedIn·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

LinkedIn SWE interview that came down to two graph problems, both island-related. Pretty focused session, no behavioral fluff, just code.

Questions Asked (2)

Q1

Given a 2D grid of '1's and '0's, count the number of islands (connected regions of land).

Algorithms & Data Structures
Author's notes

Classic BFS/DFS problem and I knew it, but I still fumbled explaining the visited tracking out loud.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Treat the grid as a graph where each land cell is a node connected to its adjacent land cells. Use DFS or BFS to explore and mark all cells in each connected component, incrementing the island count for each unvisited land cell encountered.

Pro tip: Clarify edge cases upfront (empty grid, all water, all land) and mention that you can mutate the grid to mark visited cells to save space, but ask if that's acceptable or if you should preserve the input.

1. Clarify the problem

Ask about grid dimensions, connectivity (4-directional vs 8-directional), and whether the grid can be modified. Confirm input/output format and edge cases.

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. Implement traversal and marking

Iterate through each cell; when a '1' is found, increment island count and launch a traversal to mark all connected '1's as visited (e.g., set to '0' or use a visited set).

4. Analyze complexity

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

5. Test with examples

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

Key Points to Mention

  • Graph traversal algorithms: DFS and BFS
  • Marking visited cells to avoid infinite loops
  • Time and space complexity analysis
  • Handling edge cases (empty grid, no land, all land)
  • Potential for stack overflow with recursive DFS and iterative alternative
  • In-place modification vs using extra space for visited set

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

Q2

Given a 2D grid, count the number of distinct island shapes, where two islands are considered the same if one can be translated to match the other.

Algorithms & Data Structures
Author's notes

This one got me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use DFS or BFS to identify each island, then normalize its shape by translating all coordinates relative to the top-leftmost cell. Store the normalized shape in a hash set to count distinct shapes.

Pro tip: Mention that you can optimize space by using a canonical string representation of the normalized coordinates, and discuss trade-offs between DFS and BFS for large grids.

1. Clarify the problem

Confirm that islands are connected components of 1s (4-directionally) and that translation means shifting without rotation or reflection. Ask about grid size and constraints.

2. Choose traversal method

Select DFS (recursive or iterative) or BFS to explore each island. Consider recursion depth for large grids and potential stack overflow.

3. Normalize island shape

During traversal, record the coordinates of each cell. After traversal, translate all coordinates so that the minimum row and column are 0, making the shape invariant to translation.

4. Store and count distinct shapes

Convert the normalized coordinates to a hashable form (e.g., a string or tuple of sorted coordinates) and insert into a set. The set size is the number of distinct shapes.

5. Analyze complexity

Time complexity is O(R*C) for traversal and normalization. Space complexity is O(R*C) for the visited set and shape storage. Discuss potential optimizations.

Key Points to Mention

  • Use DFS/BFS to find connected components (islands).
  • Normalize by subtracting the minimum row and column from all coordinates.
  • Use a hash set to store unique normalized shapes.
  • Time complexity O(R*C) and space complexity O(R*C).
  • Handle edge cases: empty grid, no islands, all water, all land.
  • Consider iterative DFS to avoid recursion limit for large grids.

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