Python 3 || DP || Memorisation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def minimumDistance(self, word: str) -> int:\n        col = 6\n\n        def ord_to_cor(cor: int):\n            return (cor // col, cor % col)\n\n        def distance(curr: str, target: str):\n            if curr == ".": return 0\n            cor_curr = ord_to_cor(ord(curr) - ord("A"))\n            cor_target = ord_to_cor(ord(target) - ord("A"))\n            return abs(cor_curr[0] - cor_target[0]) + abs(cor_curr[1] - cor_target[1])\n\n\n        memo = {}\n        def dfs(i: int, first: str, second: str) -> int:\n            if i == len(word): return 0\n            if (i, first, second) in memo: return memo[(i, first, second)]\n\n            memo[(i, first, second)] = min(\n                distance(first, word[i]) + dfs(i+1, word[i], second),\n                distance(second, word[i]) + dfs(i+1, first, word[i])\n            )\n            return memo[(i, first, second)]\n        \n        return dfs(0, ".", ".")\n\n\n\n\n        \n```
['Python3']