Problem
Ask
Submissions

Problem: Minimum Time Takes to Reach Destination Without Drowning

Medium
30 min
Explore how to calculate the minimum time required to reach a destination from a source cell on a grid while avoiding flooded and stone cells. Learn to apply matrix traversal methods and understand dynamic flooding to safely navigate towards the goal. This lesson equips you with strategies to handle constraints and efficiently solve grid-based pathfinding problems.

Statement

Given a m x n grid of the string land. It consists of the following types of cells:

  • S: Source cell where you are standing initially.

  • D: Destination cell where you have to reach.

  • .: These cells are empty.

  • X: These cells are stone.

  • *: These cells are flooded.

Each second, you can move to a neighboring cell directly next to your current one. At the same time, any empty cell next to a flooded cell also becomes flooded. There are two challenges in your path:

  1. You can’t step on stone cells.

  2. You can’t step on flooded cells or cells that will flood right when you try to step on them because you’ll drown.

Return the minimum time it takes you to reach the destination from the source in seconds, or 1-1 if no path exists between them.

Note: The destination will never be flooded.

Constraints:

  • 22 \leq m, n 100\leq 100

  • land consists only of S, D, ., * and X.

  • There is only one S and D cells in the land.

Problem
Ask
Submissions

Problem: Minimum Time Takes to Reach Destination Without Drowning

Medium
30 min
Explore how to calculate the minimum time required to reach a destination from a source cell on a grid while avoiding flooded and stone cells. Learn to apply matrix traversal methods and understand dynamic flooding to safely navigate towards the goal. This lesson equips you with strategies to handle constraints and efficiently solve grid-based pathfinding problems.

Statement

Given a m x n grid of the string land. It consists of the following types of cells:

  • S: Source cell where you are standing initially.

  • D: Destination cell where you have to reach.

  • .: These cells are empty.

  • X: These cells are stone.

  • *: These cells are flooded.

Each second, you can move to a neighboring cell directly next to your current one. At the same time, any empty cell next to a flooded cell also becomes flooded. There are two challenges in your path:

  1. You can’t step on stone cells.

  2. You can’t step on flooded cells or cells that will flood right when you try to step on them because you’ll drown.

Return the minimum time it takes you to reach the destination from the source in seconds, or 1-1 if no path exists between them.

Note: The destination will never be flooded.

Constraints:

  • 22 \leq m, n 100\leq 100

  • land consists only of S, D, ., * and X.

  • There is only one S and D cells in the land.