Question DSA-STR-0015
HardWhat is the output of this code?
s = "babad"
best = ""
for c in range(len(s)):
for l, r in ((c, c), (c, c + 1)):
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]
print(best)
- A.
bab
- B.
aba
- C.
Sign up free to see the answer and a step-by-step explanation.