Bounds of One Zero Rectangle
Problem statement
Given a nonempty rectangular integer matrix matrix containing only 0 and 1, return the top-left and bottom-right corners of its one zero rectangle.
For this exercise, assume there is exactly one nonempty, completely filled axis-aligned rectangle of zeros, and every other cell is one. Arbitrary shapes and overlapping rectangle decompositions are outside this valid-input contract.
For this exercise, assume coordinates are zero-based and both endpoints are inclusive. Return exactly [[top,left],[bottom,right]]; the result contains coordinates, not height and width.
Function
rectangleBounds(matrix: int[][]) → int[][]Examples
Example 1
matrix = [[1,1,1,1],[1,0,0,1],[1,0,0,1],[1,1,1,1]]return = [[1,1],[2,2]]The source matrix is retained. Roblox gives these exact corner coordinates.
Example 2
matrix = [[1,1,0,0,0],[1,1,0,0,0],[1,1,1,1,1],[1,1,1,1,1]]return = [[0,2],[1,4]]This authored example touches the top and right borders.
Example 3
matrix = [[0,0,0]]return = [[0,0],[0,2]]This authored example contains one height-one rectangle.
Constraints
- For this exercise, assume row and column counts are each from
1through30, and all rows have the same length. - Every cell is the integer
0or1. - Exactly one nonempty filled zero rectangle is present.