Question DSA-TP-0003
EasyWhat is the output of this code?
s = "racecar"
i, j = 0, len(s) - 1
ok = True
while i < j:
if s[i] != s[j]:
ok = False
break
i += 1
j -= 1
print(ok)
- A.
False
- B.
None
- C.
Show answer and explanation
Answer: D
Comparing characters from both ends inward checks for a palindrome: 'racecar' matches all the way.