Python 3 (eight lines) (beats 100%) (376 ms) (BFS w/ Memo)
```\nclass Solution:\n    def minimumDistance(self, W: str) -> int:\n        A, B, I, W = {(ord(W[0])-65,-1):0}, {}, math.inf, [ord(w)-65 for w in W]\n        d
```\nclass Solution:\n    def minimumDistance(self, W: str) -> int:\n        A, B, I, W = {(ord(W[0])-65,-1):0}, {}, math.inf, [ord(w)-65 for w in W]\n        def dist(u,v): return abs(u//6 - v//6) + abs(u % 6 - v % 6)\n        for w in W[1:]:\n            for a in A:\n                B[(w,a[1])] = min(B.get((w,a[1]),I), A[a] + dist(a[0],w))\n                B[(a[0],w)] = min(B.get((a[0],w),I), A[a] + (a[1] != -1)*dist(a[1],w))\n            A, B = B, {}\n        return min(A.values())\n\t\t\n\t\t\n- Junaid Mansuri\n- Chicago, IL
['Breadth-First Search', 'Memoization', 'Python', 'Python3']