|
| 1 | +<h2><a href="https://leetcode.com/problems/minimum-obstacle-removal-to-reach-corner/">2290. Minimum Obstacle Removal to Reach Corner</a></h2><h3>Hard</h3><hr><div><p>You are given a <strong>0-indexed</strong> 2D integer array <code>grid</code> of size <code>m x n</code>. Each cell has one of two values:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>0</code> represents an <strong>empty</strong> cell,</li> |
| 5 | + <li><code>1</code> represents an <strong>obstacle</strong> that may be removed.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>You can move up, down, left, or right from and to an empty cell.</p> |
| 9 | + |
| 10 | +<p>Return <em>the <strong>minimum</strong> number of <strong>obstacles</strong> to <strong>remove</strong> so you can move from the upper left corner </em><code>(0, 0)</code><em> to the lower right corner </em><code>(m - 1, n - 1)</code>.</p> |
| 11 | + |
| 12 | +<p> </p> |
| 13 | +<p><strong class="example">Example 1:</strong></p> |
| 14 | +<img alt="" src="https://assets.leetcode.com/uploads/2022/04/06/example1drawio-1.png" style="width: 605px; height: 246px;"> |
| 15 | +<pre><strong>Input:</strong> grid = [[0,1,1],[1,1,0],[1,1,0]] |
| 16 | +<strong>Output:</strong> 2 |
| 17 | +<strong>Explanation:</strong> We can remove the obstacles at (0, 1) and (0, 2) to create a path from (0, 0) to (2, 2). |
| 18 | +It can be shown that we need to remove at least 2 obstacles, so we return 2. |
| 19 | +Note that there may be other ways to remove 2 obstacles to create a path. |
| 20 | +</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 2:</strong></p> |
| 23 | +<img alt="" src="https://assets.leetcode.com/uploads/2022/04/06/example1drawio.png" style="width: 405px; height: 246px;"> |
| 24 | +<pre><strong>Input:</strong> grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]] |
| 25 | +<strong>Output:</strong> 0 |
| 26 | +<strong>Explanation:</strong> We can move from (0, 0) to (2, 4) without removing any obstacles, so we return 0. |
| 27 | +</pre> |
| 28 | + |
| 29 | +<p> </p> |
| 30 | +<p><strong>Constraints:</strong></p> |
| 31 | + |
| 32 | +<ul> |
| 33 | + <li><code>m == grid.length</code></li> |
| 34 | + <li><code>n == grid[i].length</code></li> |
| 35 | + <li><code>1 <= m, n <= 10<sup>5</sup></code></li> |
| 36 | + <li><code>2 <= m * n <= 10<sup>5</sup></code></li> |
| 37 | + <li><code>grid[i][j]</code> is either <code>0</code> <strong>or</strong> <code>1</code>.</li> |
| 38 | + <li><code>grid[0][0] == grid[m - 1][n - 1] == 0</code></li> |
| 39 | +</ul> |
| 40 | +</div> |
0 commit comments