Two Pointers/Easy

Valid PalindromeFREE TRACK

Time: O(N)Space: O(1)

Initialize Two Pointers

Array is sorted. Set left pointer L=0 (val 1) and right pointer R=4 (val 1).

Array Elements & Pointers
L
1
L
2
[1]
3
[2]
2
[3]
R
1
R
Live Variables & Invariants
target:4
left:0
right:4
sum:2
Step 1 / 714%
Solution Code
1
function isPalindrome(s: string): boolean {
2
  let l = 0, r = s.length - 1;
3
  while (l < r) {
4
    if (s[l] !== s[r]) return false;
5
    l++; r--;
6
  }
7
  return true;
8
}

Custom Test Case Runner

Input your custom values and visualize step-by-step trace

Quick Presets:

AI DSA Coach

Contextual Tutor for Valid Palindrome

Hello! I am your AI DSA Tutor for **Valid Palindrome** (Two Pointers). Ask me anything about this algorithm, time complexity, or request a step hint!