← All Exercises
Count Unique Grid Paths with Obstacles
intermediatepython
Background
Grid path counting introduces obstacle handling and space-compressed DP used in robotics and map analysis.
Problem
Given a grid of '.' and '#' cells, count paths from the top-left to the bottom-right moving only right or down, avoiding blocked cells.
Input
A non-empty list of equal-length strings containing only '.' for open cells and '#' for blocked cells.
Output
The number of valid monotone paths as an integer, or 0 when start or end is blocked.
Sample tests
Sample 1
Input: grid = ["..",".."]
Expected: 2
Sample 2
Input: grid = [".#.","...","..."]
Expected: 3
Sample 3
Input: grid = ["#."]
Expected: 0
Your solution
Learning objective
Compress a grid DP into one row and fold obstacle resets into the transition.