1
var getMaximumGold = function (grid) {4
// This is our internal dfs function that will search all possible directions from a cell5
const mine = (x, y, n) => {6
// We can't mine any gold if the position is out of the grid, or the cell doesnt have any gold10
x > grid.length - 1 ||11
y > grid[x].length - 1 ||16
// Save the temp value so we can mark the cell as visited17
let temp = grid[x][y];20
// Try mining left, right, up, and down from the current position,21
// bringing along the gold total that was found in the current cell22
mine(x + 1, y, n + temp);23
mine(x - 1, y, n + temp);24
mine(x, y + 1, n + temp);25
mine(x, y - 1, n + temp);27
// After we've tried all directions reset cell to have its original value,28
// so it can be mined from a different starting point31
// Update the max based on the mining done up until the current cell32
max = Math.max(max, n + temp);35
// We need to run this dfs function through every potential starting point36
for (let i = 0; i < grid.length; i++) {37
for (let j = 0; j < grid[i].length; j++) {