1136. Unique Paths II — With Obstacles

EasyDynamic ProgrammingGrid DP

A robot moves only right or down on a grid where 1 marks an obstacle and 0 is free. Return the number of distinct paths from the top-left to the bottom-right, avoiding obstacles (0 if the start or end is blocked). The input is JSON {grid}.

Input: JSON {grid}.

Output: Integer — the number of unique paths.

Examples

Example 1
Input: {"grid":[[0,0,0],[0,1,0],[0,0,0]]}
Output: 2
Explanation: Two paths avoid the center obstacle.
Example 2
Input: {"grid":[[0,1],[0,0]]}
Output: 1
Explanation: One path.
Example 3
Input: {"grid":[[0]]}
Output: 1
Explanation: Single free cell.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →