JavaScript DFS with memoization
\nvar knightProbability = function(N, K, r, c) {\n    \n    const memo = {};\n    \n    function dfs(row, col, moves) {\n        \n        const key = `${moves}
```\nvar knightProbability = function(N, K, r, c) {\n    \n    const memo = {};\n    \n    function dfs(row, col, moves) {\n        \n        const key = `${moves}:${row}:${col}`;\n        \n        if(memo[key]) {\n            return memo[key];\n        }\n        \n        if(row < 0 ||\n           row >= N ||\n           col < 0 ||\n           col >= N\n        ) {\n            return 0;\n        }\n        \n        if(moves === 0) {\n            return 1;\n        }\n        \n        let inbound = 0;\n        \n        inbound += dfs(row-2, col-1, moves-1);\n        inbound += dfs(row-1, col-2, moves-1);\n        inbound += dfs(row+1, col-2, moves-1);\n        inbound += dfs(row+2, col-1, moves-1);\n        \n        inbound += dfs(row-2, col+1, moves-1);\n        inbound += dfs(row-1, col+2, moves-1);\n        inbound += dfs(row+1, col+2, moves-1);\n        inbound += dfs(row+2, col+1, moves-1);\n        \n        memo[key] = inbound;\n        \n        return inbound;\n        \n    } \n    \n    let onboard = dfs(r, c, K);\n    return onboard/Math.pow(8,K);\n    \n};\n```
[]