PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/LinkedIn

Count connected land components in a grid

Last updated: Mar 29, 2026

Quick Overview

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.

  • medium
  • LinkedIn
  • Coding & Algorithms
  • Software Engineer

Count connected land components in a grid

Company: LinkedIn

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a 2D grid of characters where: - `'1'` represents land - `'0'` represents water A group of land cells forms an **island** if they are connected **4-directionally** (up, down, left, right). Determine the number of islands in the grid. ## Input - `grid`: an `m x n` matrix of characters (`'0'` or `'1'`). ## Output - Return an integer: the number of islands. ## Constraints - `1 <= m, n <= 300` - `grid[i][j] ∈ {'0','1'}` ## Notes - Diagonal adjacency does **not** connect islands. - You may modify the grid in-place if desired.

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.

Related Interview Questions

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Can You Place N Objects? - LinkedIn (medium)
LinkedIn logo
LinkedIn
Nov 21, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
8
0

You are given a 2D grid of characters where:

  • '1' represents land
  • '0' represents water

A group of land cells forms an island if they are connected 4-directionally (up, down, left, right). Determine the number of islands in the grid.

Input

  • grid : an m x n matrix of characters ( '0' or '1' ).

Output

  • Return an integer: the number of islands.

Constraints

  • 1 <= m, n <= 300
  • grid[i][j] ∈ {'0','1'}

Notes

  • Diagonal adjacency does not connect islands.
  • You may modify the grid in-place if desired.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More LinkedIn•More Software Engineer•LinkedIn Software Engineer•LinkedIn Coding & Algorithms•Software Engineer Coding & Algorithms
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.