Question DSA-DP-0011
MediumWhat is the output of this code?
x, y = "abcde", "ace"
dp = [[0] * (len(y) + 1) for _ in range(len(x) + 1)]
for i in range(1, len(x) + 1):
for j in range(1, len(y) + 1):
dp[i][j] = dp[i-1][j-1] + 1 if x[i-1] == y[j-1] else max(dp[i-1][j], dp[i][j-1])
print(dp[-1][-1])
- A.
3
- B.
4
- C.
Sign up free to see the answer and a step-by-step explanation.