Clean JavaScript solution
Time O(mn * 4^l), l = word.length\nSpace O(mn + l)\n\njs\nconst exist = (board, word) => {\n  if (board.length === 0) return false;\n\n  const h = board.length;
Time O(mn * 4^l), l = word.length\nSpace O(mn + l)\n\n```js\nconst exist = (board, word) => {\n  if (board.length === 0) return false;\n\n  const h = board.length;\n  const w = board[0].length;\n  const dirs = [[-1, 0], [0, 1], [1, 0], [0, -1]];\n\n  const go = (x, y, k) => {\n    if (board[x][y] !== word[k]) return false;\n    if (k === word.length - 1) return true;\n\n    board[x][y] = \'*\'; // mark as visited\n    for (const [dx, dy] of dirs) {\n      const i = x + dx;\n      const j = y + dy;\n      if (i >= 0 && i < h && j >= 0 && j < w) {\n        if (go(i, j, k + 1)) return true;\n      }\n    }\n    board[x][y] = word[k]; // reset\n    return false;\n  };\n\n  for (let i = 0; i < h; i++) {\n    for (let j = 0; j < w; j++) {\n      if (go(i, j, 0)) return true;\n    }\n  }\n\n  return false;\n};\n```\n
['JavaScript']