PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Crowdstrike
  • Coding & Algorithms
  • Software Engineer

Count connected components in a binary grid

Company: Crowdstrike

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an `m x n` grid of characters `'0'` and `'1'`: - `'1'` represents land - `'0'` represents water Two land cells are connected if they share an edge (4-directional adjacency: up/down/left/right). **Task**: Return the number of connected land components ("islands"). ### Input - `grid`: `m x n` matrix of characters `'0'`/`'1'` ### Output - An integer: the number of islands ### Constraints - `1 <= m, n <= 300` - `grid[i][j] ∈ {'0','1'}` ### Example Input: ``` 1 1 0 0 1 0 0 1 0 0 1 1 ``` Output: ``` 3 ```

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.

Return the number of 4-directionally connected components of land cells "1" in a grid of "0"/"1" characters.

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

  1. DFS or BFS from each unseen land cell.
Last updated: Jun 27, 2026

Related Coding Questions

  • Maximize the minimum value along a grid path - Crowdstrike (medium)
  • Implement templated string replacement - Crowdstrike (medium)

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.