Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Problem: What is the number of paths from (1,1) to (3,3) moving only right or up in a grid with all cells free? Run the DP.

Problem: What is the number of paths from (1,1) to (3,3) moving only right or up in a grid with all cells free? Run the DP.
g = [[1] * 4 for _ in range(4)]
for i in range(2, 4):
    for j in range(2, 4):
        g[i][j] = g[i - 1][j] + g[i][j - 1]
print(g[3][3])
What is printed?
  1. A. 20
  2. B. 4
  3. C. 9
  4. D. 6

Correct answer: D. 6

From (1,1) to (3,3) needs 2 rights and 2 ups: C(4,2) = 6, which the DP builds from the boundary 1s. Starting from (0,0) gives C(6,3) = 20, 2² = 4 ignores ordering, and 9 counts cells.

More Coding Interview Problems questions

Exams that ask this topic