My solution with 3 dp
Complexity

Time complexity:
O(n∗26∗26)


Space complexity:
O(n∗26∗26)

Code
# Complexity
- Time complexity:
$$O(n*26*26)$$

- Space complexity:
$$O(n*26*26)$$

# Code
```cpp []
class Solution {

    vector<vector<vector<int>>> dp;

    pair<int,int> find(char c){
        int ind = c-'A';
        int i = ind/6;
        int j = ind%6;
        j+= 1;

        return make_pair(i+1,j);
    }

    int dist(pair<int,int>p1,pair<int,int>p2){
        if(p1.first == 0 || p2.first == 0)
            return 0;
        return (abs(p1.first-p2.first) + abs(p1.second-p2.second));
    }

    int solve(string& word,int i,int n,pair<int,int>f1,pair<int,int>f2){
        if(i==n) return 0;
        int ans = INT_MAX;
        pair<int,int> p = find(word[i]);

        int loc1 = 6*(f1.first-1) + f1.second;
        int loc2 = 6*(f2.first-1) + f2.second;

        loc1 = loc1<0 ? 0 : loc1;
        loc2 = loc2<0 ? 0 : loc2;

        if(dp[i][loc1][loc2] != -1) return dp[i][loc1][loc2];

        //use first finger
        ans = min(ans,dist(p,f1) + solve(word,i+1,n,p,f2));

        //use second finger
        ans = min(ans,dist(p,f2) + solve(word,i+1,n,f1,p));
        dp[i][loc1][loc2] = dp[i][loc2][loc1] = ans;
        return ans;
        //return ans;
    }


public:
    int minimumDistance(string word) {
        dp = vector<vector<vector<int>>>(word.size(),vector<vector<int>>(27,vector<int>(27,-1)));
        return solve(word,0,word.size(),make_pair(0,0),make_pair(0,0));
    }
};
```
['String', 'Dynamic Programming', 'C++']