Question DSA-STR-0047
MediumWhat is the output of this code?
def lps(p):
t = [0] * len(p)
k = 0
for i in range(1, len(p)):
while k and p[i] != p[k]:
k = t[k - 1]
if p[i] == p[k]:
k += 1
t[i] = k
return t
print(lps("aabaaab"))
- A.
[0, 0, 1, 2, 2, 3, 4]
- B.
[0, 1, 0, 1, 2, 2, 3]
- C.
[0, 1, 2, 0, 1, 2, 3]
- D.
[0, 1, 0, 1, 2, 3, 3]
Sign up free to see the answer and a step-by-step explanation.