Unique paths
A cart stands in the top-left cell of a warehouse floor drawn as a grid with rows rows and cols columns. It must reach the bottom-right cell. Each move takes it one cell right or one cell down, never left or up.
Return the number of different routes from the top-left cell to the bottom-right cell. Two routes are different when their lists of moves are different. On a grid of one cell the cart is already there, and staying put counts as one route.
rows = 3, cols = 3Output6Every route makes 2 moves right (R) and 2 moves down (D) in some order: RRDD, RDRD, RDDR, DRRD, DRDR, DDRR.
rows = 2, cols = 4Output4Three R and one D. The D can go in any of 4 places: DRRR, RDRR, RRDR, RRRD.
rows = 1, cols = 5Output1A single row: the only route is four moves right.
1 ≤ rows, cols ≤ 100
Python integers do not overflow, so even very large counts come out exact.
Plan it first
Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.