Workspace Valid Palindrome Ii
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Valid Palindrome II visualizer

Learn Valid Palindrome II with a step-by-step Sliding Window & Two Pointers visualizer, JavaScript source code and a worked example. Practice opposing pointers.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 3Execution step
Reference example · JavaScript
Inspect reference input
"abca"

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
function f(l,r,b){
while(l<r){
s("Compare endpoints",{
Array:[...a],Bounds:[l,r],DeletionBudget:[b]
},[l,r]);
if(a[l]!==a[r])return b>0&&(f(l+1,r,b-1)||f(l,r-1,b-1));
l++;
r--
}
return true
}
return f(0,a.length-1,1)
};

Execution canvas

Active Changed
STEP 1

Compare endpoints

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Array4 items
Bounds2 items
DeletionBudget1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Sliding Window & Two Pointers · Opposing pointers

Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.

Example input

"abca"

Execution steps

  1. Compare endpoints

Computed output

true
JavaScript reference implementation
const solve = (a,s)=>{
  function f(l,r,b){
    while(l<r){
      s("Compare endpoints",{
        Array:[...a],Bounds:[l,r],DeletionBudget:[b]
      },[l,r]);
      if(a[l]!==a[r])return b>0&&(f(l+1,r,b-1)||f(l,r-1,b-1));
      l++;
      r--
    }
    return true
  }
  return f(0,a.length-1,1)
};

Continue learning

Practice related DSA questions in the same topic.