Unique Paths II - Javascript Clean Solution
if you start write your Recursive solution you will get TLE (Time Limit Exceed) \nso we need to have some way of Cache the result of Every Recursive Call so thi
if you start write your Recursive solution you will get TLE (Time Limit Exceed) \nso we need to have some way of Cache the result of Every Recursive Call so this technique is called \nMemomization we will have a Array called **memo** to store our Recursive Result and cache it\n\n```javascript\n/**\n * @param {number[][]} obstacleGrid\n * @return {number}\n */\n var uniquePathsWithObstacles = function (obstacleGrid) {\n  const M = obstacleGrid.length;\n  const N = obstacleGrid[0].length;\n  const memo = new Array(M).fill(0).map((v) => new Array(N).fill(0)); // 1-memo Array to Cache the Result\n\n  const traverse = (x, y) => {\n    if (obstacleGrid[x] === undefined || obstacleGrid[x][y] === undefined || obstacleGrid[x][y] === 1) return 0; // 2-check is there is Obstacle\n\n    if (x === M - 1 && y === N - 1) return 1; // 3-if we reach the Target we need\n\n    if (memo[x][y] === 0) { // 4-start to traverse at this point if === 0\n      memo[x][y] = traverse(x + 1, y) + traverse(x, y + 1);\n    }\n    return memo[x][y]; // 5-Return the result\n  };\n\n  return traverse(0, 0);\n};\n```
['Recursion', 'Memoization', 'JavaScript']