BackmediumBacktracking Zomato Adobe

Asteroid Field Navigation Solution

Problem Statement

Given a 2D grid representing an asteroid field, find the number of unique navigation paths from the top left corner to the bottom right corner.

Example 1
Input
asteroidField = [[0,0,0],[0,0,0],[0,0,0]]
Output
1

Explanation: Step-by-step: The input asteroid field is a 3x3 grid with all zeros, representing no asteroids. We can move right from the top left corner to the second cell (3) without encountering an asteroid field. Therefore, there is only one unique navigation path, which is to move right from the top left corner to the second cell.

Example 2
Input
asteroidField = [[0,1,0],[0,0,0],[0,0,0]]
Output
0

Explanation: Step-by-step: The input asteroid field is a 3x3 grid with an asteroid at the second cell. We cannot move right from the top left corner to the second cell because of the asteroid. Therefore, there are no unique navigation paths.

Constraints

  • The grid size will not exceed 20x20 cells.
  • Each cell in the grid will contain either 3 (safe path) or 8 (asteroid field).
  • The spacecraft starts at the top left corner and must reach the bottom right corner.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free