Question DSA-STR-0062
HardWhat is the output of this code?
def lps(s):
best = ""
for c in range(2 * len(s) - 1):
l, r = c // 2, (c + 1) // 2
while l >= 0 and r < len(s) and s[l] == s[r]:
l -= 1; r += 1
if r - l - 1 > len(best):
best = s[l + 1:r]
return best
print(lps("forgeeksskeegfor"))
- A.
skeeg
- B.
geeksskeeg
- C.
Sign up free to see the answer and a step-by-step explanation.