Valid Palindrome
Treat the input as a sequence of lowercase letters and return 1 if it reads identically backwards, otherwise 0.
EXECUTION LAB
Treat the input as a sequence of lowercase letters and return 1 if it reads identically backwards, otherwise 0.
Input and constraints
- Use lowercase letters encoded as 0 (a) through 25 (z).
- Use at most 32 integers. Each numeric input is between -1000 and 1000.
Code inspector
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 1Visualizer
Step 1 of 300left
11
22
31
40right
Inspect the current state
Compare the letters at 0 and 4.
Variable watch
left 0right 4
Step explanation
Compare the letters at 0 and 4.
comparisons 1reads 0writes 0swaps 0recursiveCalls 0
Educational simulation · O(n) time · O(1) space
Worked explanation
Read a line of letter tiles from both ends toward the centre.
Guided solution
Each outside pair must match before the inner sequence matters.
O(n) time · O(1) auxiliary space
Examples
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
Progressive hints
Hint 1
Read a line of letter tiles from both ends toward the centre.Hint 2
Each outside pair must match before the inner sequence matters.Hint 3
Step through the worked example and inspect the highlighted variables before each update.Common mistake
Comparing only one end pair cannot establish that the whole string is a palindrome.
Interview follow-up
How could you ignore spaces and punctuation?