/**
* @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
NFT Aggregator Marketplace Development: Everything You Need to Know in 2025
From 2021 to 2025, the NFT market has seen countless ups and downs. Some predicted the inevitable end…
Deconstructing LinkedIn’s Video Streaming: Building a High-Performance Extraction Engine with HLS and FFmpeg
Introduction As developers, we are often fascinated by how massive platforms manage data delivery at scale. LinkedIn, the…
Prompt engineering isn’t optional. It’s the new literacy that will define who thrives and who struggles.
Why Prompt Engineering is the New Literacy Jaideep Parashar ・ Sep 9 #ai #learning #machinelearning #webdev