No need to be fancy [python]
No need to be fancy. \nNo need to go bottom-up.\nNo need to keep track of a cache.\nNo need to do index math to calc distance. \nNo need to memorize the Unicode
No need to be fancy. \nNo need to go bottom-up.\nNo need to keep track of a cache.\nNo need to do index math to calc distance. \nNo need to memorize the Unicode numbers for capital letters.\n\n```python\ndef distance(p1, p2):\n    if not p1 or not p2:\n        return 0\n    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])\n\nclass Solution:\n    def minimumDistance(self, word: str) -> int:\n        grid = {}\n        row = 0\n        col = 0\n        for i in range(ord(\'A\'), ord(\'Z\') + 1):\n            grid[chr(i)] = (row, col)\n            col += 1\n            if col == 6:\n                col = 0\n                row += 1\n        \n        @lru_cache(None)\n        def calc_distance(i, f1, f2):\n            if i == len(word):\n                return 0\n            \n            return min(distance(grid[word[i]], f1) + calc_distance(i + 1, grid[word[i]], f2),\n                       distance(grid[word[i]], f2) + calc_distance(i + 1, f1, grid[word[i]]))\n        \n        return calc_distance(0, (), ()) # using falsy values for free fingers\n```
[]