/**
* @param {number[][]} grid
* @return {number}
*/
var getMaximumGold = function (grid) {
const m = grid.length
const n = grid[0].length
let res = 0
function dfs(row, col) {
if (
Math.min(row, col) < 0
|| row >= m
|| col >= n
|| grid[row][col] === 0
) return 0
let curr = grid[row][col]
grid[row][col] = 0
let down = dfs(row + 1, col)
let up = dfs(row - 1, col)
let left = dfs(row , col + 1)
let right = dfs(row , col - 1)
grid[row][col] = curr
return curr + Math.max(down, up, right, left)
}
for (let row = 0; row < m; row++) {
for (let col = 0; col < n; col++) {
res = Math.max(res, dfs(row, col))
}
}
return res
};
Related Posts
🚀💼 Lean Startup: Transforming Tech with Lean Principles 💼🚀
I’ve been captivated by The Lean Startup by Eric Ries. It masterfully adapts lean manufacturing to the tech…
Mastering CSS Animations and Transition
Cascading Style Sheets (CSS) offer powerful tools for adding interactivity and visual appeal to your web projects. Among…
Amass API – REST API Solution for Domain Reconnaissance
For a long time, I searched for a solution like this and finally decided to create my own.…