In the Find the Minimum Area to Cover All Ones II coding problem, you are asked to divide the grid into exactly three non-overlapping rectangles such that every '1' in the grid is covered by at least one of these rectangles. You need to minimize the sum of the areas of these three rectangles.
This "Hard" problem from Microsoft and Salesforce tests your ability to handle complex Enumeration and spatial partitioning. Unlike the first version, you must now consider all possible ways to split a 2D space into three regions. It evaluation your mastery of recursion or multi-step logic to solve optimization problems with geometric constraints.
This problem is solved by Enumerating Split Points. There are only a few ways to split a rectangle into three non-overlapping sub-rectangles:
Consider a large grid. A vertical cut at splits it into and . Then, a horizontal cut at splits the second part into and . You calculate the minimum area covering all 1s in these three disjoint regions and repeat for all possible and .
For spatial split problems, draw out the possible cut patterns. For , there are exactly 6 fundamental layouts. Once you identify these, the problem reduces to correctly applying the 1-rectangle solution to various sub-windows of the grid.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Check if Move is Legal | Medium | Solve | |
| Check if Word Can Be Placed In Crossword | Medium | Solve | |
| Find the Minimum Area to Cover All Ones I | Medium | Solve | |
| Valid Tic-Tac-Toe State | Medium | Solve | |
| Collecting Chocolates | Medium | Solve |