1
const dist = function (from, to) {2
if (from == -1) return 0;4
((from.charCodeAt(0) - 65) % 6) - ((to.charCodeAt(0) - 65) % 6)7
Math.floor((from.charCodeAt(0) - 65) / 6) -8
Math.floor((to.charCodeAt(0) - 65) / 6)12
var minimumDistance = function (word) {15
const dfs = function (i, lpos, rpos) {16
if (i == word.length) return 0;17
const key = [i, lpos, rpos].join(",");18
if (dp.get(key)) return dp.get(key);22
dist(lpos, word[i]) + dfs(i + 1, word[i], rpos),23
dist(rpos, word[i]) + dfs(i + 1, lpos, word[i])28
return dfs(0, -1, -1);