Question DSA-DP-0063
HardWhat is the output of this code?
def lps_len(s):
n = len(s); d = [[0] * n for _ in range(n)]
for i in range(n - 1, -1, -1):
d[i][i] = 1
for j in range(i + 1, n):
d[i][j] = d[i + 1][j - 1] + 2 if s[i] == s[j] else max(d[i + 1][j], d[i][j - 1])
return d[0][n - 1]
print(lps_len("bbbab"), lps_len("character"))
- A.
3 5
- B.
5 5
- C.
Sign up free to see the answer and a step-by-step explanation.