← 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])
- A.4
- B.9
- C.3
- 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 →