Count connected land components in a grid
Company: LinkedIn
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates understanding of grid traversal and graph connectivity concepts, focusing on modeling a 2D matrix as adjacency relationships within the coding and algorithms domain.
Constraints
- Inputs are provided as Python literals compatible with the function signature.
- Return a deterministic value exactly matching the requested output.
Examples
Input: ([['1','1','0','0'], ['1','0','0','1'], ['0','0','1','1']],)
Expected Output: 2
Explanation: Two regions.
Input: ([[1, 1], [1, 1]],)
Expected Output: 1
Explanation: One island.
Input: ([[0, 0], [0, 0]],)
Expected Output: 0
Explanation: No land.
Hints
- Start with a direct data structure representation.
- Handle edge cases before the main loop.