As reported: ServiceNow Senior Software Engineer (IC3, full stack, Hyderabad) loop, round 1, Jul 2025: a simple DP — count the paths in a grid (Unique Paths), then the follow-up with obstacles (Unique Paths II) — and resume project questions. Also asked in round 2 of a ServiceNow Staff Engineer loop (Oct 2025), where the candidate used DFS.
A robot starts at the top-left cell of an m × n grid and moves only right or down. obstacleGrid[i][j] = 1 marks an obstacle the robot cannot enter. Return the number of distinct paths to the bottom-right cell.
This is LeetCode 63 — Unique Paths II. Without obstacles it is LeetCode 62 — Unique Paths.
Example
[[0,0,0],[0,1,0],[0,0,0]] -> 2
[[0,1],[0,0]] -> 1
[[1]] -> 0
Constraints: 1 ≤ m, n ≤ 100; cells are 0 or 1; the answer is at most 2 · 10^9.
Code runner format: one line with obstacleGrid. Implement uniquePathsWithObstacles(obstacleGrid); the harness prints the count.