Skip to content

2290. Minimum Obstacle Removal to Reach Corner #887

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to model this problem using a graph where each cell in the grid is a node. The goal is to navigate from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1), while minimizing the number of obstacles (1s) we need to remove.

Approach:

  1. Graph Representation:

    • Each cell in the grid is a node.
    • Movement between adjacent cells (up, down, left, right) is treated as an edge.
    • If an edge moves through a cell with a 1 (obstacle), the cost is 1 (remove the obstacle), and if it moves through a 0 (empty cell), the cost is 0.
  2. Algorithm Choice:

    • Since we need to minimize the number of obstacles removed, we can use 0-1 BFS (Breadth-First Search with a deque) or Dijkstra's algorithm

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Nov 28, 2024
Collaborator

@mah-shamim
Comment options

mah-shamim Nov 28, 2024
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants