C++ easy solution with Memoization
\nclass Solution {\npublic:\n    unordered_map<char, int> rowMap;\n    unordered_map<char, int> colMap;\n    unordered_map<string, int> dp;\n    \n    int dista
```\nclass Solution {\npublic:\n    unordered_map<char, int> rowMap;\n    unordered_map<char, int> colMap;\n    unordered_map<string, int> dp;\n    \n    int distance(char a, char b) {\n        if(a==\'#\' || b== \'#\') {\n            return 0;\n        }\n        \n        int rowDistance = abs(rowMap[a]-rowMap[b]);\n        int colDistance = abs(colMap[a]-colMap[b]);\n        return rowDistance + colDistance;\n    }\n    \n    void initialize() {\n        for(int i=0;i<26;i++) {\n            int row = i/6;\n            int col = i%6;\n            rowMap[char(\'A\'+i)] = row;\n            colMap[char(\'A\'+i)] = col;\n        }\n    }\n    \n    int findMinDistance(string& word, int index, char finger1, char finger2) {\n        if(index == word.size()) {\n            return 0;\n        }\n        \n        string key = to_string(index)+"-"+finger1+"-"+finger2;\n        if(dp.find(key)!=dp.end()) {\n            return dp[key];\n        }\n        \n        int result1 = distance(word[index], finger1) + findMinDistance(word, index+1, word[index], finger2);\n        int result2 = distance(word[index], finger2) + findMinDistance(word, index+1, finger1, word[index]);\n        \n        dp[key] = min(result1, result2);\n        return dp[key];\n    }\n    \n    int minimumDistance(string word) {\n        initialize();\n        return findMinDistance(word, 0, \'#\', \'#\');\n    }\n};\n```
[]