#3197
Find the Minimum Area to Cover All Ones II
hard · 63.6% accepted · 402 likes · top 66%
array · matrix · enumeration
Description
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.
Solution