Back to problems

Number of Islands in a Matrix

Object-Oriented Programming · Uber · Medium

Design a class that maintains a binary matrix while supporting updates and island-count queries. A land cell has value 1, and an island consists of land cells connected through shared horizontal or vertical edges; diagonal contact does not connect cells. The class must provide operations to initialize the matrix, change an individual cell, and return the current number of islands. Consider how the design should behave when the matrix receives a large volume of modification…

Checking your access…