C++ || Easy || Explained || Recursion || Memoization
Intuition\n Describe your first thoughts on how to solve this problem. \nSimple Recursion & then memoization\n\n# Approach\n Describe your approach to solving t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimple Recursion & then memoization\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFor every move probability becomes 1/8th. So go in all possible 8 directions and add in ans. And to memoize it, you can simply use a 3-d array or a hasmap with string as key and double as value (with the separators). If probability has already been calculated, simply return.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n*n*k*8)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n*n*k)$$\n# Code\n```\nclass Solution {\n  public: unordered_map < string, double > mp;\n  int dir[8][8] = {{-2,-1},{-1,-2},{1,-2},{2,-1},{2,1},{1,2},{-1,2},{-2,1}};\n\n  double knightProbability(int n, int k, int row, int column) {\n    return solve(n, k, row, column);\n  }\n\n  double solve(int n, int moves, int r, int c) {\n    if (r < 0 || r >= n || c < 0 || c >= n) return 0;\n    if (moves == 0) return 1;\n    string key = to_string(r) + "a" + to_string(c) + "k" + to_string(moves);\n    if (mp.find(key) != mp.end()) return mp[key];\n    double ans = 0;\n    for (int i = 0; i < 8; i++)\n      ans += solve(n, moves - 1, r + dir[i][0], c + dir[i][1]) / 8.0;\n    mp[key] = ans;\n    return mp[key];\n  }\n};\n\n\n\n```
['C++']