Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created December 18, 2020 06:34
Show Gist options
  • Save manojnaidu619/cfe205a638facbc294e1a52bcb2c63f8 to your computer and use it in GitHub Desktop.
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
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