Skip to content

Right-and-down paths across a 6x6 grid and N by M

Question

A game character occupies the top-left square (1,1)(1,1) of a 6×66\times6 grid and may only step right or down.

(a) How many routes take it to the bottom-right square (6,6)(6,6)?

(b) Describe an algorithm that counts such routes on a general N×MN\times M grid.

Short answer

(a) 252252. Every route uses exactly 55 right and 55 down steps, so it is fixed by choosing which 55 of the 1010 steps go right: (105)=252\binom{10}{5}=252. (b) Either return (N+M−2N−1)\binom{N+M-2}{N-1} directly, or fill a DP table with P(i,j)=P(i−1,j)+P(i,j−1)P(i,j)=P(i-1,j)+P(i,j-1) and ones along the first row and column, which is O(NM)O(NM) time and O(min⁡(N,M))O(\min(N,M)) memory with a rolling row.

Adapted from OpenQuant; question and answer rewritten by SelfMadeQuant.com.

See the hint and the full worked solution in the question bank (free account).

Open the worked solution

Lessons behind this question

Start with a free lesson: Probability Fundamentals is part of a free topic. Create a free account, no card needed, to read it in full with worked solutions.

Read it free