You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Understand what the interviewer is asking for by using test cases and questions about the problem.
What if the string is empty?
An empty string is considered a palindrome as it reads the same forward and backward.
P-lan
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Use two pointers to compare characters from the beginning and end of the string moving towards the center.
1) Initialize two pointers, left at the start (0) and right at the end (length of s - 1)
2) While left pointer is less than right pointer:
a) If characters at left and right pointers do not match, return False
b) Increment left pointer and decrement right pointer
3) If all characters match, return True
⚠️ Common Mistakes
Forgetting to move both pointers after each comparison, which causes an infinite loop.