c++ recursion + memorization
```\nclass Solution {\npublic:\n    int dist(char a, char b) {\n        if(a == \'#\') return 0;\n        int a_row = (a - \'A\') / 6;\n        int a_col = (a -
```\nclass Solution {\npublic:\n    int dist(char a, char b) {\n        if(a == \'#\') return 0;\n        int a_row = (a - \'A\') / 6;\n        int a_col = (a - \'A\') % 6;\n        \n        int b_row = (b - \'A\') / 6;\n        int b_col = (b - \'A\') % 6;\n        \n        return abs(a_row - b_row) + abs(a_col - b_col);\n    }\n    \n    int solve(string word, char f1, char f2, int pos, map<string, int> &memo) {\n        if(pos == word.length())\n            return 0;\n        \n        string s1 = string(1, f1);\n        string s2 = string(1, f2);\n        string key = s1 + s2 + to_string(pos);\n        \n        if(memo.find(key)!=memo.end()) return memo[key];\n        int choice1 = dist(f1, word[pos]) + solve(word, word[pos], f2, pos + 1, memo);\n        int choice2 = dist(f2, word[pos]) + solve(word, f1, word[pos], pos + 1, memo);\n        memo[key] = min(choice1, choice2);\n        return memo[key];\n    }\n    \n    int minimumDistance(string word) {\n        map<string, int> memo;\n        return solve(word, \'#\', \'#\', 0, memo);\n    }\n};
[]