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