Skip to the code
cf.
+25 XP

#649 Count Grid Routes

medium

A board-game app shows a grid of rows × cols cells. A token starts in the top-left cell and must reach the bottom-right cell, moving only one cell right or one cell down at a time.

Write gridRoutes(rows, cols) that returns how many different routes there are, modulo 1000000007.

Example 1

Input: rows = 2, cols = 2
Output: 2

Right then down, or down then right.

Example 2

Input: rows = 3, cols = 3
Output: 6

Every route makes 2 down-moves and 2 right-moves. Choosing which 2 of the 4 moves go down gives C(4, 2) = 6.

Constraints

  • 1 <= rows, cols <= 1000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).