Python || Very Easy Solution || Simple Memoization
\n\'\'\'\nkeyboard :-\n       0 1 2 3 4 5\n0      a b c d e f\n1      g h i j k l\n2      m n o p q r\n3      s t u v w x\n4      y z\n\nreturn the minimum tota
```\n\'\'\'\nkeyboard :-\n       0 1 2 3 4 5\n0      a b c d e f\n1      g h i j k l\n2      m n o p q r\n3      s t u v w x\n4      y z\n\nreturn the minimum total distance to type such string using only two fingers.\nThe distance between coordinates (x1,y1) and (x2,y2) is |x1 - x2| + |y1 - y2|.\n\ninitial positions of your two fingers are considered free\nso don\'t count towards your total distance\nyour two fingers do not have to start at the first letter or\n                                    the first two letters.\n\'\'\'\n\'\'\'\nex:-   HAPPY       f1 -> H -> A -> Y\n                           2     4          6\n                   f2 -> P,P              + 0\n                                        ---------\n                                            6\n\'\'\'\n\nword = \'cake\'\n\nfrom functools import lru_cache\ndef dis(a,b):\n    if a==-1 or b==-1:\n        return 0\n    a = ord(a)-65\n    b = ord(b)-65\n    return abs(a//6-b//6) + abs(a%6-b%6)\n\ndef two_fingers(word):\n\n    @lru_cache(None)\n    def go(f1, f2, index):                 # current state : finger 1,finger 2,current char\n        if index == len(word):\n            return 0\n\n        ans = min(dis(f1,word[index] + go(word[index],f2,index+1)) ,\n                  dis(f2,word[index] + go(f1,word[index],index+1)) )\n        return ans\n\n    return go(-1,-1,0)\n\n\n\n\n```
['Dynamic Programming', 'Depth-First Search', 'Memoization', 'Python', 'Python3']