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.
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
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
};