🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: DP on Grids and Strings: all 10 questions

Quiz: DP on Grids and Strings · Question 2 of 10

What does this print? (code)

What does this print?

R, C = 3, 3
dp = [[1] * C for _ in range(R)]
for i in range(1, R):
    for j in range(1, C):
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
print(dp[2][2])
  1. A.4
  2. B.9
  3. C.3
  4. D.6
Answer & explanation

Correct answer: 6

A 3 × 3 grid needs 2 downs and 2 rights in some order: C(4, 2) = 6.

Can you get the rest right without peeking?

Take the timed Quiz: DP on Grids and Strings quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →