Skip to content

Instantly share code, notes, and snippets.

@iJustErikk
Created December 4, 2020 19:33
Show Gist options
  • Save iJustErikk/d9363b61fb89706cfe73f4338b73675d to your computer and use it in GitHub Desktop.
Save iJustErikk/d9363b61fb89706cfe73f4338b73675d to your computer and use it in GitHub Desktop.
const gridTraveler = (m, n, memo = new Map()) => {
const key = `${m},${n}`;
if (memo.has(key)) return memo.get(key);
if (m === 0 || n === 0) return 0;
if (m === 1 && n === 1) return 1;
memo.set(key, gridTraveler(m - 1, n, memo) + gridTraveler(m, n - 1, memo));
return memo.get(key);
};
console.log(gridTraveler(20, 20));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment