House Bounds in a Ragged Grid
Problem statement
A map is given as an array of strings. Rows may have different lengths. A 1 is a house cell and * is empty space. A house is a complete group of 1 cells connected through shared horizontal or vertical sides. Diagonal contact does not connect houses; a missing cell in a short row is empty space.
For each house, return the top-left and bottom-right labels of the smallest rectangle that contains all its cells and follows the grid’s rows and columns. Rows use A through Z; columns use one-based decimal numbers, so row zero and column four is A5. A house does not have to fill a rectangle. A corner of its enclosing rectangle may be an empty cell.
Return one pair [topLeft, bottomRight] per house, sorted by the numeric top row, left column, bottom row, then right column. Return an empty array when the map contains no houses.
Function
findHouseBounds(grid: String[]) → String[][]Examples
Example 1
grid = ["****111**","*11**","**11***"]return = [["A5","A7"],["B2","C4"]]The first house occupies the three adjacent cells in row A. The second bends across rows B and C and has bounding corners B2 and C4.
Example 2
grid = ["1*","*1"]return = [["A1","A1"],["B2","B2"]]Diagonal cells belong to separate houses.
Example 3
grid = ["*1","11"]return = [["A1","B2"]]One connected L-shaped house has a bounding top-left corner at A1 even though that cell is empty.
Constraints
0 <= grid.length <= 26.0 <= grid[r].length <= 26; rows may have different lengths.- Every existing cell is
1or*.