Skip to content
Discussion options

You must be logged in to vote

We need to find the minimum total area of three non-overlapping rectangles that cover all the 1's in a given binary grid. The rectangles must have horizontal and vertical sides and can touch but not overlap. The solution involves enumerating all possible ways to split the grid into three regions using horizontal and vertical lines, then calculating the sum of the areas of the bounding boxes of the 1's in each region.

Approach

  1. Precompute Ones: First, we gather all the coordinates of the 1's in the grid.
  2. Bounding Box Area Calculation: We define a helper function to compute the area of the bounding box for a set of points. The area is calculated as (max_row - min_row + 1) * (max_col - min_c…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Aug 23, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Aug 23, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants