CPP || Recursion + Memoization || 5D Dp
IDEA : For every character in word, we have two choices, either put the 1st finger on it or put the second finger, we will take both the cases into account and 
IDEA : For every character in word, we have two choices, either put the 1st finger on it or put the second finger, we will take both the cases into account and return the minimum.\n```\nclass Solution {\npublic:\n\t//dp table where 1st value represent current index of the word, 2nd and 3rd value represents cell number for 1st finger and 4th and 5th  value represents cell number for 2nd finger\n    int dp[305][5][6][5][6];\n    vector<pair<int, int>> grid;\n    int f(string& word, int i, int n, int x1, int y1, int x2, int y2){\n        if(i >= n) return 0;\n\t\t//taking MOD otherwise our dp table will excceed the memory limit as it will be something like dp[305][26][26][26][26], if we take each cell into consideration.\n        if(dp[i][x1 % 5][y1 % 6][x2 % 5][y2 % 6] != -1) return dp[i][x1 % 5][y1 % 6][x2 % 5][y2 % 6];\n        int op1 = 1e9, op2 = 1e9;\n        int x = grid[word[i] - \'A\'].first, y = grid[word[i] - \'A\'].second;\n\t\t//op1 represents value if 1st finger is placed at current index\n        op1 = abs(x - x1) + abs(y - y1) + f(word, i+1, n, x, y, x2, y2);\n\t\t//op2 represents value if 2nd finger is placed at current index\n        op2 = abs(x - x2) + abs(y - y2) + f(word, i+1, n, x1, y1, x, y);\n        return  dp[i][x1 % 5][y1 % 6][x2 % 5][y2 % 6] = min(op1, op2);\n    }\n    int minimumDistance(string word) {\n        int n = word.size();\n        int ans = INT_MAX;\n        memset(dp, -1, sizeof(dp));\n\t\t//build our grid..grid[0] = {0, 0}...grid[1] = {0, 1}...and so on, where gid[0] represents cell value for \'A\', grid[1] represents cell value of \'B\' and so on...\n        for(int i=0; i<5; ++i)\n            if(i != 4) for(int j=0; j<6; ++j) grid.push_back({i, j});\n            else for(int j=0; j<2; ++j) grid.push_back({i, j});\n\t\t//We will take every possibility of starting point i.e, 1st finger on A -> {2nd on A, 2nd finger on B......2nd finger on Z}, 1st finger on B -> {2nd finger on A, 2nd finger on B.....2nd finger on Z} and so on...\n        for(int i=0; i<26; ++i){\n            for(int j=0; j<26; ++j){\n\t\t\t\t// (x1, y1) represents cell number for 1st finger and (x2, y2) represents cell number for 2nd finger\n                int x1 = grid[i].first, x2 = grid[j].first;\n                int y1 = grid[i].second, y2 = grid[j].second;\n                ans = min(ans, f(word, 0, n, x1, y1, x2, y2));\n                \n            }\n        }\n        return ans;\n    }\n};
['Dynamic Programming', 'Recursion', 'Memoization', 'C']