← Samsung Interview Insights

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

Intermediate
Jun 2026

Summary

Samsung coding screen, basically just the classic islands problem. Nothing fancy, no behavioral, straight into the algorithm.

Questions Asked (1)

Q1

Given a binary grid of 1s and 0s, count the number of islands, where an island is a group of adjacent land cells connected in four directions.

Algorithms & Data Structures
Author's notes

Classic problem, knew it cold.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a graph traversal algorithm like 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 adjacent land cells and count distinct sets.

Pro tip: Discuss the trade-offs between DFS (recursive, may cause stack overflow for large grids) and BFS (iterative, uses queue) and mention that Union-Find is efficient for dynamic connectivity but may be overkill for static grids.

1. Clarify the problem

Confirm the definition of adjacency (4-directional), input format (2D array of integers), and expected output (integer count). Ask about edge cases like empty grid or all water.

2. Choose an algorithm

Select a traversal method (DFS or BFS) or Union-Find. Explain why it's suitable: DFS/BFS are simple and efficient for this problem; Union-Find can be used but may be less intuitive.

3. Outline the algorithm

Describe the steps: iterate through each cell; if it's land and unvisited, increment island count and perform traversal to mark all connected land cells as visited.

4. Analyze complexity

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

5. Handle edge cases and optimizations

Mention handling empty grid, using visited matrix or modifying grid in-place to save space, and potential stack overflow with DFS for large grids.

Key Points to Mention

  • Graph traversal algorithms: DFS (recursive/iterative) and BFS
  • Union-Find (Disjoint Set Union) as an alternative approach
  • Time and space complexity analysis
  • In-place modification of the grid to mark visited cells (e.g., changing 1 to 0)
  • Handling edge cases: empty grid, no land, all land
  • Trade-offs between different approaches (e.g., recursion depth vs. queue memory)

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