|
| 1 | +<h2><a href="https://leetcode.com/problems/find-the-minimum-area-to-cover-all-ones-i">3461. Find the Minimum Area to Cover All Ones I</a></h2><h3>Medium</h3><hr><p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1's in <code>grid</code> lie inside this rectangle.</p> |
| 2 | + |
| 3 | +<p>Return the <strong>minimum</strong> possible area of the rectangle.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<div class="example-block"> |
| 9 | +<p><strong>Input:</strong> <span class="example-io">grid = [[0,1,0],[1,0,1]]</span></p> |
| 10 | + |
| 11 | +<p><strong>Output:</strong> <span class="example-io">6</span></p> |
| 12 | + |
| 13 | +<p><strong>Explanation:</strong></p> |
| 14 | + |
| 15 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/08/examplerect0.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 279px; height: 198px;" /></p> |
| 16 | + |
| 17 | +<p>The smallest rectangle has a height of 2 and a width of 3, so it has an area of <code>2 * 3 = 6</code>.</p> |
| 18 | +</div> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | + |
| 22 | +<div class="example-block"> |
| 23 | +<p><strong>Input:</strong> <span class="example-io">grid = [[1,0],[0,0]]</span></p> |
| 24 | + |
| 25 | +<p><strong>Output:</strong> <span class="example-io">1</span></p> |
| 26 | + |
| 27 | +<p><strong>Explanation:</strong></p> |
| 28 | + |
| 29 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/08/examplerect1.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 204px; height: 201px;" /></p> |
| 30 | + |
| 31 | +<p>The smallest rectangle has both height and width 1, so its area is <code>1 * 1 = 1</code>.</p> |
| 32 | +</div> |
| 33 | + |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>1 <= grid.length, grid[i].length <= 1000</code></li> |
| 39 | + <li><code>grid[i][j]</code> is either 0 or 1.</li> |
| 40 | + <li>The input is generated such that there is at least one 1 in <code>grid</code>.</li> |
| 41 | +</ul> |
0 commit comments