[Python] Top-Down DP
Go over every character in the input word and recursively check if it is more favorable to move the finger at key a or the finger at key b to that character. Us
Go over every character in the input word and recursively check if it is more favorable to move the finger at key a or the finger at key b to that character. Using None as a special input for the distance function elegantly handles initially unpositioned fingers.\n```python\nfrom functools import lru_cache\n\nclass Solution:\n    def minimumDistance(self, word: str) -> int:\n        word_length = len(word)\n        \n        def distance(char_a: str, char_b: str) -> int:\n            if not char_a or not char_b:\n                return 0\n            \n            index_a = ord(char_a) - 65\n            index_b = ord(char_b) - 65\n            \n            return abs(index_a // 6 - index_b // 6) + abs(index_a % 6 - index_b % 6)\n        \n        @lru_cache(None)\n        def find(char_index: int, key_a: str, key_b: str) -> int:\n            if char_index == word_length:\n                return 0\n            \n            char = word[char_index]\n            \n            return min(\n                find(char_index + 1, key_a, char) + distance(key_b, char),\n                find(char_index + 1, char, key_b) + distance(key_a, char)\n            )\n        \n        return find(0, None, None)\n```
['Dynamic Programming', 'Python']