Easy DP Approach
dp[i][x1][y1][x2][y2] -- stores the optimal answer for a substring s[i,....] when the 1st finger is at coordinate x1, y1 and 2nd finger is at coordinate x2,y2.\
dp[i][x1][y1][x2][y2] -- stores the optimal answer for a substring s[i,....] when the 1st finger is at coordinate x1, y1 and 2nd finger is at coordinate x2,y2.\n\nx1,y1 or x2,y2 == 7,7 indicates that the particular finger will be used for typing for the 1st time so there will be no cost in that move. 7,7 is chosen since no character corresponds to this coordinate and simply indicate that the particular finger has not been used for typing\n\n```\n#define ff first\n#define ss second\nclass Solution {\n    pair<int,int> pts[30]; // coordinate for a char\n    int n; // stores length of string\n    string t;\n    int dp[305][8][8][8][8];  \n    \npublic:\n\t// cost of moving finger from one char to another\n    int cost(int x1,int y1,int x2,int y2){\n        return abs(x1-x2)+abs(y2-y1);\n    }\n    \n    int solver(int x1,int y1,int x2,int y2,int s){\n\t\t// if string is completely traversed so return 0\n        if(s==n)\n            return 0;\n        \n\t\t// coordinates of next char to move to\n        int r=pts[t[s]-\'A\'].ff,c=pts[t[s]-\'A\'].ss;\n        \n\t\t// unvisited state\n        if(dp[s][x1][y1][x2][y2]!=-1)\n            return dp[s][x1][y1][x2][y2];\n        \n        dp[s][x1][y1][x2][y2]=INT_MAX;\n        int nxt=INT_MAX,cl=0,cr=0;\n        \n        // if typing the char with left hand\n        if(x1==7)\n            nxt=solver(r,c,x2,y2,s+1); // using left finger 1st time\n        else\n            nxt=min(nxt,cost(x1,y1,r,c)+solver(r,c,x2,y2,s+1)); // not 1st time\n        \n        // if typing the char with right hand\n        if(x2==7)\n            nxt=min(nxt,solver(x1,y1,r,c,s+1)); // right finger 1st time\n        else\n            nxt=min(nxt,cost(x2,y2,r,c)+solver(x1,y1,r,c,s+1)); // not 1st time\n        \n        return dp[s][x1][y1][x2][y2]=nxt;\n    }\n    \n    int minimumDistance(string s) {\n        char c=\'A\';\n        for(int i=0;i<4;i++)\n            for(int j=0;j<6;j++){\n                pts[c-\'A\']={i,j};\n                c++;\n            }\n        \n        t=s;\n        n=s.length();\n        \n        memset(dp,-1,sizeof(dp));\n        \n        pts[\'Y\'-\'A\']={4,0};\n        pts[\'Z\'-\'A\']={4,1};\n        \n        // x1=7, y1=7, x2=7, y2=7 meaning that both fingers havent been used for typing\n        return solver(7,7,7,7,0);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C', 'C++']