❇ maximum-number-of-moves-in-a-grid👌 🏆O(N)❤️ Javascript❤️ Memory👀95.45%🕕With Explanation ✍️ 🔴🔥
\ngetNeighbors():\n1. Takes the grid and coordinates of a cell as input.\n2. Checks if neighboring cells in the up-right direction are within the grid boundarie
```\ngetNeighbors():\n1. Takes the grid and coordinates of a cell as input.\n2. Checks if neighboring cells in the up-right direction are within the grid boundaries and adds them to the neighbors array.\n3. Returns the array containing neighboring cell coordinates.\n\nfunction getNeighbors(array, rowIndex, columnIndex) {\n    const neighbors = [];\n    if (array[rowIndex] && array[rowIndex][columnIndex + 1] !== undefined) {\n        neighbors.push({\n            rowIndex: rowIndex,\n            columnIndex: columnIndex + 1,\n        });\n    }\n    if (\n        array[rowIndex - 1] &&\n        array[rowIndex - 1][columnIndex + 1] !== undefined\n    ) {\n        neighbors.push({\n            rowIndex: rowIndex - 1,\n            columnIndex: columnIndex + 1,\n        });\n    }\n    if (\n        array[rowIndex + 1] &&\n        array[rowIndex + 1][columnIndex + 1] !== undefined\n    ) {\n        neighbors.push({\n            rowIndex: rowIndex + 1,\n            columnIndex: columnIndex + 1,\n        });\n    }\n    return neighbors;\n}\n\n1. Initializes a memoization object to store calculated results.\n2. Iterates through each cell in the leftmost column of the grid.\n3. Calls explore() for each cell and updates the output variable with the maximum moves obtained from any starting cell.\n4. Returns the maximum moves minus 1 (to account for the starting move).\n\nvar maxMoves = function (grid) {\n    const memoize = {};\n\nRecursive function to explore possible paths from the given cell [rIndex, cIndex].\n1. Checks the neighboring cells obtained from getNeighbors().\n2. If the current cell\'s height is less than the height of the neighboring cell, it explores that cell recursively.\n3. Uses memoization to store the maximum moves possible from each cell to avoid redundant calculations.\n4. Returns the maximum number of moves from the current cell.\n\n\n    const explore = function (grid, rIndex, cIndex,) {\n        let maxDistanceTraveled = 0;\n        if (memoize[`${rIndex}_${cIndex}`] !== undefined) {\n            return memoize[`${rIndex}_${cIndex}`];\n        }\n        const neighbors = getNeighbors(grid, rIndex, cIndex);\n        for (const { rowIndex, columnIndex } of neighbors) {\n            if (grid[rIndex][cIndex] < grid[rowIndex][columnIndex]) {\n                const tempMax = explore(grid, rowIndex, columnIndex,);\n                memoize[`${rowIndex}_${columnIndex}`] = tempMax;\n                if (tempMax > maxDistanceTraveled) {\n                    maxDistanceTraveled = tempMax;\n                }\n            }\n        }\n        return 1 + maxDistanceTraveled;\n    };\n\n    let output = -Infinity;\n    for (let rowIndex = 0; rowIndex < grid.length; rowIndex++) {\n        for (\n            let columnIndex = 0;\n            columnIndex < 1;\n            columnIndex++\n        ) {\n            const maxDistanceTraveled = explore(grid, rowIndex, columnIndex);\n            if (maxDistanceTraveled > output) {\n                output = maxDistanceTraveled\n            }\n            memoize[`${rowIndex}_${columnIndex}`] = maxDistanceTraveled;\n        }\n    }\n    return output - 1;\n};\n```
['JavaScript']