Created
December 18, 2020 06:34
-
-
Save manojnaidu619/cfe205a638facbc294e1a52bcb2c63f8 to your computer and use it in GitHub Desktop.
You are a traveller on a 2d grid. You begin in the top-left corner and your goa is to travel to the bottom-right corner. You may only move down/right
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gridTraveler = (m, n, memo={}) => { | |
const key = `${m},${n}` | |
if (key in memo) return memo[key] | |
if (m === 1 && n === 1) return 1 | |
if (m === 0 || n === 0) return 0 | |
memo[key] = gridTraveler(m - 1, n, memo) + gridTraveler(m, n - 1, memo) | |
return memo[key] | |
} | |
console.log(2,2) // 2 | |
console.log(gridTraveler(18,18)) //2333606220 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment