Tap here to switch tabs
Problem
Ask
Submissions

Problem: Shortest Path in a Grid with Obstacles Elimination

med
30 min
Explore how to determine the shortest path in a grid while eliminating obstacles up to a limit. Understand graph traversal methods to navigate through a grid matrix and implement algorithms that optimize pathfinding under constraints. This lesson helps you apply these concepts to solve real-world problems involving grids and obstacles.

Statement

Given an m x n integer matrix grid, where each cell contains either 00 (empty) or 11 (obstacle), you may move one step at a time in any of the four directions (up, down, left, right), but only into empty cells.

Return the minimum number of steps required to travel from the upper-left corner ((0, 0)) to the lower-right corner ((m - 1, n - 1)), given that you are allowed to eliminate at most k obstacles along the way. If no such path exists, return 1-1.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 11 \leq m, n 40\leq 40

  • 11 \leq k \leq m * n

  • grid[i][j] is either 00 or 11

  • grid[0][0] == grid[m - 1][n - 1] == 0

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Shortest Path in a Grid with Obstacles Elimination

med
30 min
Explore how to determine the shortest path in a grid while eliminating obstacles up to a limit. Understand graph traversal methods to navigate through a grid matrix and implement algorithms that optimize pathfinding under constraints. This lesson helps you apply these concepts to solve real-world problems involving grids and obstacles.

Statement

Given an m x n integer matrix grid, where each cell contains either 00 (empty) or 11 (obstacle), you may move one step at a time in any of the four directions (up, down, left, right), but only into empty cells.

Return the minimum number of steps required to travel from the upper-left corner ((0, 0)) to the lower-right corner ((m - 1, n - 1)), given that you are allowed to eliminate at most k obstacles along the way. If no such path exists, return 1-1.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 11 \leq m, n 40\leq 40

  • 11 \leq k \leq m * n

  • grid[i][j] is either 00 or 11

  • grid[0][0] == grid[m - 1][n - 1] == 0