Grid Paths
You are given an n x n grid whose squares are either empty (.) or have a trap (*).
Your task is to calculate the number of paths from the upper-left square (0, 0) to the lower-right square (n-1, n-1). You can only move right or down.
Since the answer can be large, return it modulo 109 + 7.
Example 1:
Input: n = 4, grid = ["....", ".*..", "...*", "*..."]
Output : 3
Explanation : The grid contains blocked cells marked by '*'. Counting all valid paths from
(0,0) to (3,3) using only right and down moves while avoiding blocked cells
gives a total of 3 paths.
Example 2:
Input: n = 3, grid = ["...", ".*.", "..."]
Output: 2
Explanation:
We start at the top-left cell (0,0) and need to reach the bottom-right cell (2,2).
Cells marked with '*' are blocked and cannot be used. Movement is allowed only
to the right or downward.
The cell (1,1) is blocked, which prevents paths that pass through the center.
Considering the allowed moves and avoiding the blocked cell, there are exactly
2 valid paths from the start to the destination.
Now Your Turn!
Pick the correct output for the given inputInput: n = 3, grid = ["..*", "...", "*.."]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 1000