PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Bloomberg

Count islands and implement BFS variant

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to apply grid and graph traversal concepts—counting connected components with four-directional connectivity—implement breadth-first search variants, and reason about correctness and linear-time (O(mn)) complexity.

  • Medium
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Count islands and implement BFS variant

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Given a 2D grid of characters '1' (land) and '0' (water), count the number of distinct land regions where connectivity is four-directional (up, down, left, right). Implement a solution of your choice that runs in O(mn) time and explain its correctness and complexity. Then implement a second version that uses breadth-first search explicitly. Handle edge cases such as an empty grid, all-water grid, and very large dimensions, and provide tests to validate your solution on multiple nontrivial cases.

Quick Answer: This question evaluates a candidate's ability to apply grid and graph traversal concepts—counting connected components with four-directional connectivity—implement breadth-first search variants, and reason about correctness and linear-time (O(mn)) complexity.

Related Interview Questions

  • Solve meeting and tree problems - Bloomberg (easy)
  • Minimize travel cost with two cities - Bloomberg (easy)
  • Check connectivity between two subway stations - Bloomberg (easy)
  • Design a data structure for dynamic top‑K frequency - Bloomberg (hard)
  • Find tree root and bucket numbers - Bloomberg (hard)
Bloomberg logo
Bloomberg
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0

Given a 2D grid of characters '1' (land) and '0' (water), count the number of distinct land regions where connectivity is four-directional (up, down, left, right). Implement a solution of your choice that runs in O(mn) time and explain its correctness and complexity. Then implement a second version that uses breadth-first search explicitly. Handle edge cases such as an empty grid, all-water grid, and very large dimensions, and provide tests to validate your solution on multiple nontrivial cases.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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