27 · Shortest Paths

#2290 Minimum Obstacle Removal to Reach Corner

Hardsolve on LeetCode ↗

frequently reported atGoogle

the problem

In plain words

grid has 0 (empty) and 1 (obstacle). Move up/down/left/right from (0, 0) to (m − 1, n − 1). Return the minimum number of obstacles you must remove.

in grid = [[0,1,1],[1,1,0],[1,1,0]]

out 2

in grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]]

out 0

A clear path already exists.

  • 1 ≤ m, n ≤ 10⁵
  • 2 ≤ m·n ≤ 10⁵
  • grid[0][0] == grid[m−1][n−1] == 0

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #1368
    2. #542
      01 Matrix
      Mediumin Graphs
    3. #1091