> For the complete documentation index, see [llms.txt](https://junnie.gitbook.io/wayfair/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://junnie.gitbook.io/wayfair/oa/karat/find-all-rectangles.md).

# Find all rectangles

<https://stackoverflow.com/questions/65411142/finding-rectangles-in-the-image><br>

<https://www.geeksforgeeks.org/find-rectangles-filled-0/><br>

for the same image, it is filled with 0s and 1s. It may have multiple rectangles filled with 0s. The rectangles are separated by 1s. Find all the rectangles.

```
public class Main {
    public List<List<Integer>> findMultipleRectangle(int[][] board)
    {
        List<List<Integer>> res = new ArrayList<>();

        for(int i = 0; i< board.length; i++)
        {
            for (int j = 0; j< board[0].length; j++)
            {
                if(board[i][j] == 0)
                {
                    List<Integer> rectangle = new ArrayList<Integer>();
                    rectangle.add(i);
                    rectangle.add(j);
                    board[i][j] = 1;

                    int topLeftX = i;
                    int topLeftY = j;
                    while(topLeftX < board.length && board[topLeftX][j] == 0)
                    {
                        board[topLeftX][j] = 1;
                        topLeftX++;
                    }
                    while(topLeftY < board[0].length && board[i][topLeftY] == 0)
                    {
                        board[i][topLeftY] = 1;
                        topLeftY++;
                    }
                    rectangle.add(topLeftX);
                    rectangle.add(topLeftY);
                    res.add(rectangle);
                }
            }
        }
        return rectangle;
    }
}
```
