C++ || memo+recursion || Easy-approach
\nclass Solution {\npublic:\n  int dp[301][5][6][5][6][2];\n   int helper(string &word,int start,int prevXfing1,int prevYfing1,int prevXFing2,int prevYFing2,boo
```\nclass Solution {\npublic:\n  int dp[301][5][6][5][6][2];\n   int helper(string &word,int start,int prevXfing1,int prevYfing1,int prevXFing2,int prevYFing2,bool finger2,unordered_map<char,pair<int,int>>&mp){\n       if(start==word.length()) return 0;\n     if(dp[start][prevXfing1][prevYfing1][prevXFing2][prevYFing2][finger2]!=-1) \n       return dp[start][prevXfing1][prevYfing1][prevXFing2][prevYFing2][finger2];\n      int currstartX= mp[word[start]].first; \n     int currstartY= mp[word[start]].second; \n     if(finger2){\n        int op1= abs(currstartX-prevXfing1)+abs(currstartY-prevYfing1)+helper(word,start+1,currstartX,currstartY,prevXFing2,prevYFing2,finger2,mp);\n        int op2= abs(currstartX-prevXFing2)+abs(currstartY-prevYFing2)+ helper(word,start+1,prevXfing1,prevYfing1,currstartX,currstartY,finger2,mp);\n       return dp[start][prevXfing1][prevYfing1][prevXFing2][prevYFing2][finger2]=min(op1,op2);\n        }\n      else{\n          int op1= abs(currstartX-prevXfing1)+abs(currstartY-prevYfing1)+helper(word,start+1,currstartX,currstartY,prevXFing2,prevYFing2,finger2,mp);\n        int op2= helper(word,start+1,prevXfing1,prevYfing1,currstartX,currstartY,true,mp);\n        return dp[start][prevXfing1][prevYfing1][prevXFing2][prevYFing2][finger2]=min(op1,op2);\n      }\n    \n   \n      \n   }\n    int minimumDistance(string word) {\n       for(int i=0;i<word.length();i++) word[i]=tolower(word[i]);\n     // cout<<word;\n        unordered_map<char,pair<int,int>>mp;\n        mp[\'a\']={0,0};\n      mp[\'b\']={0,1};\n      mp[\'c\']={0,2};\n      mp[\'d\']={0,3};mp[\'e\']={0,4};mp[\'f\']={0,5};\n      mp[\'g\']={1,0};mp[\'h\']={1,1};\n      mp[\'i\']={1,2};mp[\'j\']={1,3};mp[\'k\']={1,4};mp[\'l\']={1,5};\n      mp[\'m\']={2,0};mp[\'n\']={2,1};mp[\'o\']={2,2};mp[\'p\']={2,3};mp[\'q\']={2,4};\n      mp[\'r\']={2,5};mp[\'s\']={3,0};mp[\'t\']={3,1};mp[\'u\']={3,2};mp[\'v\']={3,3};\n      mp[\'w\']={3,4};mp[\'x\']={3,5};mp[\'y\']={4,0};\n      mp[\'z\']={4,1};\n      memset(dp,-1,sizeof(dp));\n        return helper(word,1,mp[word[0]].first,mp[word[0]].second,0,0,false,mp);\n    }\n};\n```
[]