PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Samsung

Count islands in a binary grid

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to analyze grid-based data structures and identify connected components, testing spatial adjacency reasoning and state management within 2D arrays.

  • easy
  • Samsung
  • Coding & Algorithms
  • Software Engineer

Count islands in a binary grid

Company: Samsung

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem You are given an `m x n` grid of characters where each cell is either `'1'` (land) or `'0'` (water). An **island** is formed by connecting adjacent land cells **horizontally or vertically** (not diagonally). The grid edges are surrounded by water. Return the **number of islands** in the grid. ## Input - `grid`: a 2D array/list of characters `'0'` and `'1'` ## Output - An integer: the number of islands ## Constraints - `1 <= m, n <= 300` - `grid[i][j] ∈ {'0','1'}` ## Example Input: ``` [ ['1','1','0','0','0'], ['1','1','0','0','0'], ['0','0','1','0','0'], ['0','0','0','1','1'] ] ``` Output: ``` 3 ``` Explanation: There are three disconnected land components.

Quick Answer: This question evaluates a candidate's ability to analyze grid-based data structures and identify connected components, testing spatial adjacency reasoning and state management within 2D arrays.

Related Interview Questions

  • Maximize sum of non-adjacent values - Samsung (medium)
  • Validate palindrome with constraints - Samsung (Medium)
Samsung logo
Samsung
Feb 12, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0

Problem

You are given an m x n grid of characters where each cell is either '1' (land) or '0' (water). An island is formed by connecting adjacent land cells horizontally or vertically (not diagonally). The grid edges are surrounded by water.

Return the number of islands in the grid.

Input

  • grid : a 2D array/list of characters '0' and '1'

Output

  • An integer: the number of islands

Constraints

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

Example

Input:

[
  ['1','1','0','0','0'],
  ['1','1','0','0','0'],
  ['0','0','1','0','0'],
  ['0','0','0','1','1']
]

Output:

3

Explanation: There are three disconnected land components.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Samsung•More Software Engineer•Samsung Software Engineer•Samsung Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.