Problem · Matrix
Find Largest House Area
Learn this problemProblem 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[][]) → intExamples
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 = 3The area of the biggest house is 3.
So, the output is 3.
Constraints
- Every grid cell is either
0or1.