Unique Paths

Write the code, see it run, pass the checks.

The problem

  • medium
  • Code

Write uniquePaths(rows, cols): a robot starts in the top-left square of a grid of rows by cols squares, and can only move one square right or one square down. Return how many different routes take it to the bottom-right square. rows and cols are whole numbers of at least 1, and rows + cols is at most 58, so the answer stays below 2 to the power 53. For example, uniquePaths(3, 2) is 3: right, down, down; down, right, down; or down, down, right. The checks include a 29 by 29 grid, with over 7 quadrillion routes, so following them one by one is too slow.

Your code must pass

  • Counts the routes through a small grid
  • Handles a single row or column
  • Is fast enough for a 29 by 29 grid