Continue learning
Practice related DSA questions in the same topic.
Treat the input as a sequence of lowercase letters and return 1 if it reads identically backwards, otherwise 0.
Treat the input as a sequence of lowercase letters and return 1 if it reads identically backwards, otherwise 0.
def solve(values, target): left = 0 right = (len(values) - 1) while (left < right): if (values[left] != values[right]): return 0 left = (left + 1) right = (right - 1) return 1Compare the letters at 0 and 4.
Compare the letters at 0 and 4.
Read a line of letter tiles from both ends toward the centre.
Each outside pair must match before the inner sequence matters.
O(n) time · O(1) auxiliary space
Worked example · {"values":[0,1,2,1,0],"target":0} ⇒ 1
Edge case 1 · {"values":[1,0],"target":0} ⇒ 0
Edge case 2 · {"values":[],"target":0} ⇒ 1
Comparing only one end pair cannot establish that the whole string is a palindrome.
How could you ignore spaces and punctuation?