✅ Easiest Solution | Recursion + Memoization [3d] | Dekh to sahi ✅
// we know there are 8 possible direction so each valid position will contribute 1/8=0.125 to the probabity \n\n// I have stored all the possible moves in 8 dir
// we know there are 8 possible direction so each valid position will contribute 1/8=0.125 to the probabity \n\n// I have stored all the possible moves in 8 direction vector which will help us to move in all possible coordinates from a position\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> directions = {{2, 1}, {1, 2}, {-1, 2}, {2, -1}, {-1, -2}, {-2, -1}, {1, -2}, {-2, 1}};\n    \n    double knightProbability(int n, int k, int row, int col) {\n        vector<vector<vector<double>>> memo(k + 1, vector<vector<double>>(n, vector<double>(n, -1.0)));\n        return backtrack(n, k, row, col, memo);\n    }\n    \n    double backtrack(int n, int k, int row, int col, vector<vector<vector<double>>>& memo) {\n        if (row < 0 || row >= n || col < 0 || col >= n)\n            return 0.0;\n        \n        if (k == 0)\n            return 1.0;\n        \n        if (memo[k][row][col] != -1.0)\n            return memo[k][row][col];\n        \n        double probability = 0.0;\n        for (const auto& dir : directions) {\n            int newRow = row + dir[0];\n            int newCol = col + dir[1];\n            probability += 0.125 * backtrack(n, k - 1, newRow, newCol, memo);\n        }\n        \n        memo[k][row][col] = probability;\n        return probability;\n    }\n};\n\n```
['C++']