AlgoMaster Logo

Unique Paths II

Ashish

Ashish Pratap Singh

medium

Problem Description

Solve it on LeetCode

Approaches

1. Recursive Backtracking

Intuition:

The recursive backtracking approach is a brute force method where we explore every possible path from the starting point to the destination, taking into account obstacles. This involves trying to move right and down at each step recursively.

Code:

2. Memoization

Intuition:

Memoization will be used to store results of already computed paths for each grid cell to avoid redundant calculations. This is an optimization to the recursive approach.

Code:

3. Dynamic Programming

Intuition:

Using a table to systematically compute the number of unique paths to each cell, considering obstacles.

Code:

4. Dynamic Programming with Space Optimization

Intuition:

By leveraging the fact that we only need the previous row and previous column to calculate the current cell's paths, we can optimize the space to O(n) using a single array.

Code: