A. Initialize dp[i,j] = 0 if obstacleGrid[i,j] == 1; else dp[i,j] = dp[i-1,j] + dp[i,j-1] (with boundary checks). Initialize first row and column carefully considering obstacles.
B. Ignore obstacles and calculate dp as usual because obstacles don't affect path count.
C. Set dp[i,j] = 1 for all cells and subtract 1 for obstacles at the end.
D. Use recursion without memoization to handle obstacles.
Solution
Step 1: Set dp to 0 where obstacles exist
For cells with obstacleGrid[i,j] == 1, dp[i,j] must be 0 to block paths.
Step 2: Calculate dp with obstacle checks
For other cells, dp[i,j] = dp[i-1,j] + dp[i,j-1], ensuring no paths through obstacles. Initialize first row and column carefully to stop paths after obstacles.
Final Answer:
Initialize dp[i,j] = 0 if obstacleGrid[i,j] == 1; else dp[i,j] = dp[i-1,j] + dp[i,j-1] (with boundary checks). Initialize first row and column carefully considering obstacles. -> Option A
Quick Check:
Obstacles block paths, set dp=0 there [OK]
Hint: Set dp=0 on obstacles, sum neighbors otherwise [OK]
Common Mistakes:
Ignoring obstacles in dp calculation
Not initializing first row/column correctly with obstacles
Using recursion without memoization causing inefficiency
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.