Question DSA-STR-0061
HardWhat is the output of this code?
def z(s):
n = len(s); z = [0] * n; l = r = 0
for i in range(1, n):
if i < r:
z[i] = min(r - i, z[i - l])
while i + z[i] < n and s[z[i]] == s[i + z[i]]:
z[i] += 1
if i + z[i] > r:
l, r = i, i + z[i]
return z
print(z("aabxaab"))
- A.
[0, 1, 0, 0, 3, 1, 0]
- B.
[7, 1, 0, 0, 3, 1, 0]
- C.
Sign up free to see the answer and a step-by-step explanation.