educative.io

Palindrome String Processing

Hi, Can you please clarify what’s the extra space used for? What is the purpose of having replace(" “,”")?


Course: https://www.educative.io/courses/data-structures-algorithms-in-python
Lesson: https://www.educative.io/courses/data-structures-algorithms-in-python/g7ZJxAzBPPG

Hi @Narayana_Sarma !!
The replace(" ", "") part removes spaces from the original string s so that the comparison of the modified string with its reverse is accurate. It ensures that spaces are not considered when determining if the string is a palindrome.
I hope it helps. Happy Learning :blush: