Java DP easy to understand with explanation
We asume a finger is at position j if row*6 + col  =  j.\n\nIf the finger is at position 26, it means the finger has no position yet.\n\nLet dp[i][j][k] be the 
We asume a finger is at position ```j``` if ```row*6 + col  =  j```.\n\nIf the finger is at position 26, it means the finger has no position yet.\n\nLet ```dp[i][j][k]``` be the minimum distance to build the substring from ```word``` from index ```i``` untill the end of the word, given that currently the fingers are on positions ```j``` and ```k``` respectively.\n\nThe transition function will be:\n\n```dp[i][j][k] = Math.min(dp[i+1][target][k] + distance1,dp[i+1][j][target] + distance2);```\n\nWhere ```target``` is the position of the character we are trying to move one of the fingers to, since we are going to move that finger to that new position. ```distance1``` would be the distance from finger 1 to the target position and ```distance2``` would be the distance from finger 2 to the target position.\n\nThen all we need to do is return ```dp[0][26][26]```, since both fingers start with no position.\n\n```\nclass Solution {\n    \n    public int move(int source, int target){\n        if(source == 26) return 0;\n        int y = source / 6;\n        int x = source % 6;\n        int y2 = target / 6;\n        int x2 = target % 6;\n        return Math.abs(y2-y) + Math.abs(x2-x);\n    }\n    \n    public int minimumDistance(String word) {\n        int[][][] dp = new int[word.length()+1][27][27];\n        for(int i=word.length()-1;i>=0;i--){\n            for(int j=0;j<27;j++){\n                for(int k=0;k<27;k++){\n                    int f1move = move(j,word.charAt(i)-\'A\');\n                    int f2move = move(k,word.charAt(i)-\'A\');\n                    dp[i][j][k] = Math.min(dp[i+1][word.charAt(i) - \'A\'][k] + f1move,dp[i+1][j][word.charAt(i) - \'A\'] + f2move);\n                }\n            }  \n        }\n\n        return dp[0][26][26];\n    }\n}\n```
[]