Simplest Code 👌👌 || Recursion to Memoization || ✅Beginner Friendly Code and Intuition || C++
Recursion\n\nclass Solution {\npublic:\n\nint dx[8]={ 2, 1, -1, -2, -2, -1, 1, 2 };\nint dy[8]={ 1, 2, 2, 1, -1, -2, -2, -1 };\n\ndouble dfs(int i,int j,int k, 
# Recursion\n```\nclass Solution {\npublic:\n\nint dx[8]={ 2, 1, -1, -2, -2, -1, 1, 2 };\nint dy[8]={ 1, 2, 2, 1, -1, -2, -2, -1 };\n\ndouble dfs(int i,int j,int k, int n){\n    if(i < 0 || j < 0 ||i >= n || j >= n) return 0;\n    if(k == 0) return 1;\n\n    double temp = 0;\n\n    for(int l = 0;l < 8; l++){\n      int x = i + dx[l];\n      int y = j + dy[l];\n      temp += dfs(x,y,k-1,n);\n    }\n    return (temp/8.0);\n}\n\n    double knightProbability(int n, int k, int row, int column) {\n        return dfs(row,column,k,n); \n    }\n};\n```\n\n# Memoization\n```\nclass Solution {\npublic:\n\ndouble dp[30][30][105];\nint dx[8]={ 2, 1, -1, -2, -2, -1, 1, 2 };\nint dy[8]={ 1, 2, 2, 1, -1, -2, -2, -1 };\n\ndouble dfs(int i,int j,int k, int n){\n    if(i < 0 || j < 0 ||i >= n || j >= n) return 0;\n    if(k == 0) return 1;\n    if(dp[i][j][k] != 0) return dp[i][j][k];\n\n    double temp = 0;\n\n    for(int l = 0;l < 8; l++){\n      int x = i + dx[l];\n      int y = j + dy[l];\n      temp += dfs(x,y,k-1,n);\n    }\n    return dp[i][j][k] += (temp/8.0);\n}\n\n    double knightProbability(int n, int k, int row, int column) {\n        memset(dp,0,sizeof(dp));\n        return dfs(row,column,k,n); \n    }\n};\n```
['C++']