Skip to content

Instantly share code, notes, and snippets.

@samuelcar
Created September 15, 2015 10:42
Show Gist options
  • Select an option

  • Save samuelcar/9296c0c97021c0d93e96 to your computer and use it in GitHub Desktop.

Select an option

Save samuelcar/9296c0c97021c0d93e96 to your computer and use it in GitHub Desktop.
Solving the "Number of Paths" problem using JavaScript
var numberOfPaths = function(matrix, i, j, size) {
var count = 0;
if (i == size - 1 && j == size - 1) {
return matrix[i][j];
}
if (i == size - 1) {
return matrix[i][j + 1]
}
if (j == size - 1) {
return matrix[i + 1][j]
}
if (matrix[i][j] == 1) {
return numberOfPaths(matrix, i + 1, j, size) + numberOfPaths(matrix, i, j + 1, size);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment