Implement the uniquePathsWithBlockedCells method that counts grid paths while avoiding blocked cells.

The input contains a grid with rows rows and cols columns. A value of 0 means the cell is open, and a value of 1 means the cell is blocked.

Your task is to count the number of unique paths from the top-left cell to the bottom-right cell while avoiding blocked cells. From each cell, you may move only right or down. If the start or end cell is blocked, the answer is 0.

Example 1
Input:
grid (int[][]) = [[0,0,0],[0,1,0],[0,0,0]]
rows (int) = 3
cols (int) = 3
Return:
(int) 2
Example 2
Input:
grid (int[][]) = [[0,1],[0,0]]
rows (int) = 2
cols (int) = 2
Return:
(int) 1
Example 3
Input:
grid (int[][]) = [[1]]
rows (int) = 1
cols (int) = 1
Return:
(int) 0

Use dynamic programming, but blocked cells must contribute zero paths.

If a cell is blocked, set its path count to 0. If it is open, its path count is the sum of paths from the top cell and the left cell.

The start cell has one path only when it is open. After all cells are processed, the bottom-right value is the answer.

Pseudocode:

function uniquePathsWithBlockedCells(grid, rows, cols):
    if rows == 0 or cols == 0:
        return 0
    if grid[0][0] == 1:
        return 0
    dp = 2D array of size rows x cols filled with 0
    dp[0][0] = 1
    for r from 0 to rows - 1:
        for c from 0 to cols - 1:
            if grid[r][c] == 1:
                dp[r][c] = 0
            else:
                if r > 0:
                    dp[r][c] = dp[r][c] + dp[r - 1][c]
                if c > 0:
                    dp[r][c] = dp[r][c] + dp[r][c - 1]
    return dp[rows - 1][cols - 1]
Run your code to see the result.