PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of grid-based graph traversal and connected-component detection, focusing on flood-fill logic and the treatment of boundary-connected regions in a binary grid.

  • medium
  • Oracle
  • Coding & Algorithms
  • Data Scientist

Count Interior Islands After Flooding

Company: Oracle

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an `m x n` binary grid representing land and water. - `1` = land - `0` = water An **island** is a maximal group of land cells connected 4-directionally (up, down, left, right). A **closed island** is an island that does **not** touch the boundary of the grid. Equivalently, you may imagine first flooding away every land cell that is connected to any boundary land cell, and then counting how many connected land components remain. Write a function that returns the number of closed islands in the grid. Clarifications: - Two land cells belong to the same island if they are connected horizontally or vertically. - Any island that touches the first/last row or first/last column should **not** be counted. - You may solve this using DFS, BFS, or Union-Find.

Quick Answer: This question evaluates understanding of grid-based graph traversal and connected-component detection, focusing on flood-fill logic and the treatment of boundary-connected regions in a binary grid.

Count 4-directional land components of 1s that do not touch the boundary.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([[0,0,0,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]],)

Expected Output: 1

Explanation: One closed island.

Input: ([[1,1],[1,0]],)

Expected Output: 0

Explanation: Boundary land not counted.

Hints

  1. Model object-style prompts as operation streams when needed.
  2. Handle empty and boundary cases before the main logic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.

Related Coding Questions

  • Implement Queue Operations Using Two Stacks - Oracle (hard)
  • 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)