✔️✔️||3D DP|| Clean Code || Intuitive || Memoisation || DP||Well commented💬💬
\nclass Solution {\n    vector<vector<vector<int>>>dp;\n    int dist(int from ,int to){\n        \n        //since we have 6 columns and 6 rows \n              
```\nclass Solution {\n    vector<vector<vector<int>>>dp;\n    int dist(int from ,int to){\n        \n        //since we have 6 columns and 6 rows \n                    \n        \n        //if hover state then return 0 as it will be starting point of finger\n        //or first char to be typed\n        if(from==26){\n            return 0;\n        }\n        \n        int x1,x2,y1,y2;\n     \n        //extracting the positions \n        \n        x1=from/6;\n        y1=from%6;\n        \n        x2=to/6;\n        y2=to%6;\n        \n        \n        return abs(x2-x1)+abs(y2-y1);\n        \n        \n    }\n    \n    \n    int minDist(string word,int pos,int leftFingerAt,int rightFingerAt ){\n        \n        if(pos==word.length()){\n            return 0;\n        }\n        \n        if(dp[pos][leftFingerAt][rightFingerAt]!=-1){\n            return dp[pos][leftFingerAt][rightFingerAt];\n        }\n         \n        int  to=word[pos]-\'A\';\n        \n        //print character with leftFinger\n        int choice1=dist(leftFingerAt,to)+minDist(word,pos+1,to,rightFingerAt);\n        \n        //print character with rightFinger\n        int choice2=dist(rightFingerAt,to)+minDist(word,pos+1,leftFingerAt,to);\n        \n        return dp[pos][leftFingerAt][rightFingerAt]= min(choice1,choice2);\n         \n    }\n    \npublic:\n\n    int minimumDistance(string word) {\n        \n        //27 bcoz we have 27 places to move fingers \n        dp.resize(word.length(),vector<vector<int>>(27,vector<int>(27,-1)));\n        \n        // here 26 means the fingers are in hover state i.e not on any letter\n        return minDist(word,0,26,26);\n        \n    }\n};\n```
['Dynamic Programming', 'Memoization']