InferenceAI

Enter at least two characters to search.

Start free

Grid Paths With Walls

mediumDynamic Programming25 min25 XP

Count the paths from the top-left to the bottom-right of grid, moving only right or down, without entering cells that are 1 (blocked).

Examples

EXAMPLE WALKTHROUGHone wall

A guided view of the published example, not a trace of your code.

INPUT[[[0,0,0],[0,1,0],[0,0,0]]]
TASKgrid_paths_with_walls()
EXPECTED OUTPUT2

Start with the input values shown in this example.

Example 1 of 3

Input: grid = [[0,0,0],[0,1,0],[0,0,0]]

Output: 2

Explanation: one wall

Input: grid = [[0,1],[0,0]]

Output: 1

Explanation: single route

Input: grid = [[1]]

Output: 0

Explanation: start blocked

Hint 1

paths[r][c] = paths[r - 1][c] + paths[r][c - 1], and 0 for blocked cells.

Topics

DSADynamic ProgrammingPython