PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Oracle

Count Enclosed Islands in a Grid

Last updated: Mar 29, 2026

Quick Overview

This question evaluates grid traversal and graph concepts such as connected-component detection, boundary-condition reasoning, and algorithmic time/space complexity analysis in two-dimensional arrays.

  • medium
  • Oracle
  • Coding & Algorithms
  • Data Scientist

Count Enclosed Islands in a Grid

Company: Oracle

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an `m x n` grid representing land and water after flooding. - `0` represents land. - `1` represents water. - Two land cells belong to the same island if they are connected vertically or horizontally (4-directional adjacency). Return the number of **enclosed islands**: connected components of land (`0`s) that **do not touch the boundary** of the grid. Any island that touches the outer border of the grid is **not** counted. Example: - If a land region is fully surrounded by water, it counts. - If any cell in that region lies on the first/last row or first/last column, it does not count. Discuss an algorithmic approach, its time and space complexity, and how you would implement it using DFS or BFS.

Quick Answer: This question evaluates grid traversal and graph concepts such as connected-component detection, boundary-condition reasoning, and algorithmic time/space complexity analysis in two-dimensional arrays.

Related Interview Questions

  • Solve Five Coding Problems - Oracle (medium)
  • Compute letter frequencies from encoded string - Oracle (medium)
  • Count closed islands in a grid - Oracle (easy)
  • Implement in-memory data structures and booking API - Oracle (hard)
  • Implement an LRU cache - Oracle (medium)
Oracle logo
Oracle
Jan 3, 2026, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
2
0
Loading...

You are given an m x n grid representing land and water after flooding.

  • 0 represents land.
  • 1 represents water.
  • Two land cells belong to the same island if they are connected vertically or horizontally (4-directional adjacency).

Return the number of enclosed islands: connected components of land (0s) that do not touch the boundary of the grid. Any island that touches the outer border of the grid is not counted.

Example:

  • If a land region is fully surrounded by water, it counts.
  • If any cell in that region lies on the first/last row or first/last column, it does not count.

Discuss an algorithmic approach, its time and space complexity, and how you would implement it using DFS or BFS.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Oracle•More Data Scientist•Oracle Data Scientist•Oracle Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

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