Robot Paths Around Blocked Tiles
A warehouse floor is a grid where 0 is a free tile and 1 is blocked. A robot starts on the top-left tile and must reach the bottom-right tile, moving only right or down, and never onto a blocked tile.
Return the number of different paths, modulo 1000000007. If the start or the goal is blocked, the answer is 0.
Example 1
Input: grid = [[0,0,0],[0,1,0],[0,0,0]] Output: 2 Explanation: Around the block either over the top or along the left.
Example 2
Input: grid = [[0,1],[0,0]] Output: 1
Constraints
- 1 <= rows, cols <= 100
- grid[r][c] is 0 or 1
Hint 1
The number of paths into a tile is the paths into the tile above plus the paths into the tile on the left.
Hint 2
A blocked tile has 0 paths. One row of the table is enough memory.
Discussion 0
Join free to post in the discussion.
Good practice for: Game Developer, Embedded Systems Engineer, Backend Developer, AI Engineer (LLM & Generative AI), Automation Test Engineer
Run checks your code on 3 sample tests. Submit runs all 9 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.