Question DSA-DP-0042
MediumWhat is the output of this code?
def lcs(a, b):
d = [[0] * (len(b) + 1) for _ in range(len(a) + 1)]
for i in range(1, len(a) + 1):
for j in range(1, len(b) + 1):
d[i][j] = d[i-1][j-1] + 1 if a[i-1] == b[j-1] else max(d[i-1][j], d[i][j-1])
return d[-1][-1]
print(lcs("AGGTAB", "GXTXAYB"))
- A.
6
- B.
3
- C.
Sign up free to see the answer and a step-by-step explanation.