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

Palindrome Partitioning visualizer

Learn Palindrome Partitioning with a step-by-step Recursion & Backtracking visualizer, JavaScript source code and a worked example. Practice constraint search.

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 / 7Execution step
Reference example · JavaScript
Inspect reference input
"aab"

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let o=[];
function f(i,p){
s("Explore partition",{
Path:p,Remaining:[a.slice(i)],Solutions:o
});
if(i===a.length){
o.push(p);
return
}
for(let j=i+1;
j<=a.length;
j++){
let w=a.slice(i,j);
if(w===[...w].reverse().join(""))f(j,[...p,w])
}
}
f(0,[]);
return o
};

Execution canvas

Active Changed
STEP 1

Explore partition

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

Path0 items

Empty at this step.

Remaining1 items
Solutions0 items

Empty at this step.

Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Recursion & Backtracking · Constraint search

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

"aab"

Execution steps

  1. Explore partition

Computed output

[
  [
    "a",
    "a",
    "b"
  ],
  [
    "aa",
    "b"
  ]
]
JavaScript reference implementation
const solve = (a,s)=>{
  let o=[];
  function f(i,p){
    s("Explore partition",{
      Path:p,Remaining:[a.slice(i)],Solutions:o
    });
    if(i===a.length){
      o.push(p);
      return
    }
    for(let j=i+1;
    j<=a.length;
    j++){
      let w=a.slice(i,j);
      if(w===[...w].reverse().join(""))f(j,[...p,w])
    }
  }
  f(0,[]);
  return o
};

Continue learning

Practice related DSA questions in the same topic.