first map the keys and then pick fingers and perform operations
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int dp[301][8][8][8][8];\n\n    // Function to calculate Manhattan distance\n    int cost(int r_prev, int c_prev, int r, int c) {\n        return abs(r_prev - r) + abs(c_prev - c);\n    }\n\n    // Recursive function to compute minimum distance\n    int f(int i, int r1, int c1, int r2, int c2, unordered_map<char, pair<int, int>>& m, string& word) {\n        if (i >= word.size()) {\n            return 0; // Base case: all characters are processed\n        }\n\n        // Return memoized result if available\n        if (dp[i][r1][c1][r2][c2] != 1e9) {\n            return dp[i][r1][c1][r2][c2];\n        }\n\n        int res = 1e9;\n        int r = m[word[i]].first;  // Get row of current character\n        int c = m[word[i]].second; // Get column of current character\n\n        // Move first finger\n        if (r1 == 7) {\n            res = f(i + 1, r, c, r2, c2, m, word); // First finger not yet placed\n        } else {\n            res = min(res, cost(r1, c1, r, c) + f(i + 1, r, c, r2, c2, m, word));\n        }\n\n        // Move second finger\n        if (r2 == 7) {\n            res = min(res, f(i + 1, r1, c1, r, c, m, word)); // Second finger not yet placed\n        } else {\n            res = min(res, cost(r2, c2, r, c) + f(i + 1, r1, c1, r, c, m, word));\n        }\n\n        return dp[i][r1][c1][r2][c2] = res; // Memoize result\n    }\n\n    // Main function to calculate minimum distance to type the word\n    int minimumDistance(string word) {\n        unordered_map<char, pair<int, int>> m;\n        int x = 0, y = 0;\n\n        // Fill map with keyboard coordinates for each character\n        for (char c = \'A\'; c <= \'Z\'; c++) {\n            m[c] = {x, y};\n            y++;\n            if (y % 6 == 0) {\n                y = 0;\n                x++;\n            }\n        }\n\n        // Initialize dp array with 1e9 (infinity)\n        std::fill(&dp[0][0][0][0][0], &dp[0][0][0][0][0] + sizeof(dp) / sizeof(dp[0][0][0][0][0]), 1e9);\n\n        // Start recursion with both fingers not placed (represented by (7,7))\n        return f(0, 7, 7, 7, 7, m, word);\n    }\n};\n\n```
['C++']