Simple Short Python code 300 ms
python\nclass Solution:\n    def minimumDistance(self, word: str) -> int:\n        chars = \'\'.join(a for a, b in zip(word, word[1:] + " ") if a != b)\n       
```python\nclass Solution:\n    def minimumDistance(self, word: str) -> int:\n        chars = \'\'.join(a for a, b in zip(word, word[1:] + " ") if a != b)\n        idx = {c: divmod((ord(c) - 65), 6) for c in string.ascii_uppercase}\n        \n        def dist(a, b):\n            if not a or not b:\n                return 0\n            ia, ja = idx[a]\n            ib, jb = idx[b]\n            return abs(ia-ib) + abs(ja-jb)\n        \n        @lru_cache(None)\n        def dp(i, wa=None, wb=None):\n            if i == len(chars): return 0 \n            xa = dist(wa, chars[i]) + dp(i + 1, chars[i], wb)\n            xb = dist(wb, chars[i]) + dp(i + 1, wa, chars[i])\n            return min(xa, xb)\n\n        return dp(0)\n```
[]