Count connected components in a binary grid
Company: Crowdstrike
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates understanding of graph traversal and connected-components detection on a 2D grid, measuring the ability to model grid cells as nodes with four-directional adjacency and reason about connectivity.
Constraints
- Use 4-directional adjacency
Examples
Input: ([['1', '1', '0', '0'], ['1', '0', '0', '1'], ['0', '0', '1', '1']],)
Expected Output: 2
Input: ([['0']],)
Expected Output: 0
Input: ([['1', '1'], ['1', '1']],)
Expected Output: 1
Hints
- DFS or BFS from each unseen land cell.