Problem · Matrix

Find Largest House Area

Learn this problem
EasyHSBCOA

Problem statement

A residential area is represented by an N by M grid. A cell containing part of a house roof has value 1, while a vacant plot has value 0.

A house is a cluster of cells with value 1 connected horizontally or vertically. Diagonal contact does not connect two cells into the same house. The area of a house is the number of cells it contains.

Return the area of the largest house.

Function

findLargestHouseArea(grid: int[][]) → int

Examples

Example 1

grid = [[0, 0, 0, 0, 0], [0, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 1, 0, 0]]return = 3
The area of the biggest house is 3. So, the output is 3.

Constraints

  • Every grid cell is either 0 or 1.

More HSBC problems

drafts saved locally
public int findLargestHouseArea(int[][] grid) {
  // write your code here
}
grid[[0, 0, 0, 0, 0], [0, 1, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 1, 0, 0]]
expected3
checking account