Easy Recursive solution using DP | C++
basic point is to keep track of both the finger\'s current cells (x, y).\nfor each finger perform recursive calls and find minimum of both fingers.\n\n# Code\n\
basic point is to keep track of both the finger\'s current cells (x, y).\nfor each finger perform recursive calls and find minimum of both fingers.\n\n# Code\n```\nclass Solution {\npublic:\n    vector<pair<int, int>> mp;\n    int dp[301][7][7][7][7];\n    int solve(int i, int finger1X, int finger1Y, int finger2X, int finger2Y, string & word) {\n        if(i >= word.size())\n            return 0;\n\n        if(dp[i][finger1X+1][finger1Y+1][finger2X+1][finger2Y+1] != -1)\n            return dp[i][finger1X+1][finger1Y+1][finger2X+1][finger2Y+1];\n\n        int x = mp[word[i] - \'A\'].first;\n        int y = mp[word[i] - \'A\'].second;\n        int finger1cost = finger1X == -1 ? 0 : abs(x- finger1X) + abs(y - finger1Y);\n        int finger2cost = finger2X == -1 ? 0 : abs(x- finger2X) + abs(y - finger2Y);\n        int finger1 = finger1cost + solve(i+1, x, y, finger2X, finger2Y, word);\n        int finger2 = finger2cost + solve(i+1, finger1X, finger1Y, x, y, word);\n        return dp[i][finger1X+1][finger1Y+1][finger2X+1][finger2Y+1] = min(finger1, finger2);\n    }\n\n    int minimumDistance(string word) {\n        memset(dp, -1, sizeof(dp));\n        mp.resize(26);\n        int cnt = 0;\n        for(int i=0; i<4; i++) {\n            for(int j=0; j<6; j++) {\n                mp[cnt++] = {i, j};\n            }\n        }\n        mp[cnt++] = {4, 0};\n        mp[cnt++] = {4, 1};\n        \n        return solve(0, -1, -1, -1, -1, word);\n    }\n};\n```
['C++']