Skip to content

Practice Find the Minimum Area to Cover All Ones II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3197
LeetCode Problem

Find the Minimum Area to Cover All Ones II

Problem Statement

You are given a 2D binary array grid. You need to find 3 non-overlapping rectangles having non-zero areas with horizontal and vertical sides such that all the 1's in grid lie inside these rectangles. Return the minimum possible sum of the area of these rectangles. Note that the rectangles are allowed to touch.

Source: Find the Minimum Area to Cover All Ones II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[1,0,1],[1,1,1]]
Output
5

# Example 2

Input
grid = [[1,0,1,0],[0,1,0,1]]
Output
5

Constraints

1 <= grid.length, grid[i].length <= 30
grid[i][j] is either 0 or 1.
The input is generated such that there are at least three 1's in grid.

Related LeetCode Problems

Practice more problems similar to Find the Minimum Area to Cover All Ones II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.