Problem · Dynamic Programming
Count Paths from the Top Left to the Bottom Right
Learn this problemProblem statement
A robot starts in the top-left cell of a grid with rows rows and columns columns. It must reach the bottom-right cell.
From each cell, the robot may move exactly one cell right or exactly one cell down. Return the total number of distinct valid paths.
Function
countGridPaths(rows: int, columns: int) → longExamples
Example 1
rows = 3columns = 4return = 10Every path contains two down moves and three right moves; there are 10 orderings.
Example 2
rows = 1columns = 7return = 1Only repeated right moves are possible.
Example 3
rows = 5columns = 5return = 70There are 70 ways to arrange four down and four right moves.
Constraints
1 <= rows, columns <= 30.- The answer fits in a signed 64-bit integer.