Compare values at both ends12.05
Ends are a[L] and a[R]. Comparing them decides which end to consume in two-pointer scans (palindrome checks, merging from outsides).
After the comparison, move the pointer whose value you have finished with. Do not move both unless the algorithm says so.
Same skill, three traces. Read all three before you try it.
01palindrome check - given
a = [1, 9, 9, 1]- walk
a[0]==a[3]a[1]==a[2]- result
- ends match twice → palindrome
02mismatch - given
a = [1, 9, 8, 1]- walk
0and3match1and2:9≠8- result
- not a palindrome
03single center - given
a = [1, 4, 1]- walk
ends
1==1LmeetsRat4- result
- palindrome
endsPalindrome(a).a is an array of integers. L starts at 0. R starts at n-1.While
L < R, compare a[L] and a[R]. Print each comparison. If they differ, return false. Then add 1 to L and subtract 1 from R.[1, 9, 9, 1] → true. [1, 9, 8, 1] → false. [1, 4, 1] → true.constraintsa is non-empty.
- Container With Most Water0/3 skills ready · two pointers · mediumopen
- Container With Most Water0/3 skills ready · two pointers · mediumopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.