functionnumberOfWaysToTraverseGraph(width, height) {constm=newArray(height); m[0] =newArray(width).fill(1);for (let i =1; i < height; i++) { m[i] =newArray(width).fill(0); m[i][0] =1; }let total =0;for (let i =1; i < height; i++) {for (let j =1; j < width; ++j) { m[i][j] = m[i -1][j] + m[i][j -1]; } }console.log(m);return m[height -1][width -1];}// Do not edit the line below.exports.numberOfWaysToTraverseGraph = numberOfWaysToTraverseGraph;
n + m, 1
Combination 7 Combination 3
// 7! / (3! * 4!)functionnumberOfWaysToTraverseGraph(width, height) {constnumerator=factorial(width -1+ height -1);constdenominator=factorial(width -1) *factorial(height -1);returnMath.floor(numerator / denominator);}functionfactorial(n) {let result =1;for (let i = n; i >=1; --i) { result *= i; }return result;}// Do not edit the line below.exports.numberOfWaysToTraverseGraph = numberOfWaysToTraverseGraph;