← Samsung Interview Insights

Samsung·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Samsung SWE interview, got a grid traversal problem that felt pretty standard but I still managed to overthink parts of it. Not much else to say about the round itself.

Questions Asked (1)

Q1

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

Algorithms & Data Structures
Author's notes

I went with DFS and marked visited cells by flipping them to '0' in place.

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 and mark all connected land cells as visited, incrementing the island count for each traversal. Alternatively, use Union-Find to group connected land cells and count distinct sets. The key is to systematically visit each cell and avoid revisiting.

Pro tip: Clarify edge cases upfront (empty grid, all water, all land) and discuss trade-offs between DFS (recursive, risk of stack overflow) and BFS (iterative, uses queue) or Union-Find (efficient for dynamic connectivity). Mentioning these shows depth and prevents follow-up pitfalls.

1. Clarify the problem

Confirm grid dimensions, connectivity definition (4-directional), and whether diagonal connections count. Ask about input constraints (size, memory) and expected output.

2. Choose an algorithm

Select DFS, BFS, or Union-Find based on constraints. For most interviews, DFS/BFS is straightforward; Union-Find is elegant for large grids or streaming data.

3. Outline the traversal

Iterate through each cell; when encountering an unvisited '1', increment island count and launch a traversal 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) for recursion stack or queue in worst case (all land).

5. Test with examples

Walk through a small grid (e.g., 3x3) to verify correctness, including edge cases like a single island, multiple islands, and no islands.

Key Points to Mention

  • Graph traversal techniques: DFS (recursive/iterative) and BFS
  • Union-Find (Disjoint Set Union) as an alternative approach
  • Time and space complexity analysis
  • Handling edge cases: empty grid, all water, all land, large grids
  • In-place modification vs. visited matrix for marking visited cells
  • Potential follow-ups: counting distinct island shapes, largest island, or number of islands in a stream

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