C++ Top Down DP
```\nclass Solution {\n    vector>> dp;\n    \n    int getCharDist(char a, char b) {\n        int x1 = (a-\'A\') / 6, y1 = (a-\'A\') % 6;\n        int x2 = (b-\
```\nclass Solution {\n    vector<vector<vector<int>>> dp;\n    \n    int getCharDist(char a, char b) {\n        int x1 = (a-\'A\') / 6, y1 = (a-\'A\') % 6;\n        int x2 = (b-\'A\') / 6, y2 = (b-\'A\') % 6; \n        return abs(x1 - x2) + abs(y1 - y2);\n    }\n    \n    int rec(const string& word, int kthCharPos, char firstFingerAt, char secondFingerAt) {\n        if (word.size() == kthCharPos) return 0;\n        \n        int& ret = dp[kthCharPos][firstFingerAt-\'A\'][secondFingerAt-\'A\'];\n        if (ret != -1) return ret;\n        \n        int moveFirstFinger = rec(word, kthCharPos+1, word[kthCharPos], secondFingerAt) + getCharDist(firstFingerAt, word[kthCharPos]);\n        int moveSecondFinger = rec(word, kthCharPos+1, firstFingerAt, word[kthCharPos]) + getCharDist(secondFingerAt, word[kthCharPos]);\n        \n        return ret = min(moveFirstFinger, moveSecondFinger);\n    }\n    \npublic:\n    int minimumDistance(string word) {\n        dp.resize(word.size(), vector<vector<int>>(26, vector<int>(26, -1)));\n        int minDist = INT_MAX;\n\n        for (char c = \'A\'; c <= \'Z\'; c++) {\n            minDist = min(minDist, rec(word, 0, word[0], c));\n        }\n        \n        return minDist;\n    }\n};
['Dynamic Programming', 'Recursion', 'C']