Solución
solution.tsTypeScript
function countPaths(rows: number, cols: number): number {
const matrix = Array.from({ length: rows }, () => Array(cols).fill(1))
for (let i = 1; i < rows; i++) {
for (let j = 1; j < cols; j++) {
matrix[i][j] = matrix[i - 1][j] + matrix[i][j - 1]
}
}
/*
Ejemplo countPaths(3, 3)
1 1 1 1 1 1 1 1 1 1 1 1
1 -> 1 2 -> 1 2 3 -> 1 2 3
1 1 1 3 1 3 6
*/
return matrix[rows - 1][cols - 1];
}
// No modificar: necesario para evaluar el resultado.
export { countPaths };0respuestas