/**
* @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
Fine-Tuning: Unlocking Precision and Performance in AI Models
Fine-tuning has emerged as a cornerstone technique in the development and deployment of high-performance artificial intelligence models. As…
Mastering Fuzzy Search with Manticore Search
Fuzzy search represents a family of techniques that enable intelligent matching between search queries and content. At its…
Loop functions in synchronous way #React Quick Notes.
We all know term called Recursion. That is same we are doing in below example to loop through…