#3197

Find the Minimum Area to Cover All Ones II

expert · 1120 · lc hard +32 · 63.6% accepted · 402 likes · top 66%

Description

You are given a 2D binary array grid. Place 3 non-overlapping axis-aligned rectangles (each with positive area) so that every 1 in grid lies inside at least one of them.

Return the minimum possible sum of the three rectangle areas.

Note that rectangles are allowed to touch each other.

Code

1
2
3