Workspace Longest Palindromic Substring
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Longest Palindromic Substring visualizer

Learn Longest Palindromic Substring with a step-by-step Strings visualizer, JavaScript source code and a worked example. Practice fundamentals and parsing.

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

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let b="";
for(let i=0;
i<a.length;
i++)for(let d=0;
d<2;
d++){
let l=i,r=i+d;
while(l>=0&&r<a.length&&a[l]===a[r]){
if(r-l+1>b.length)b=a.slice(l,r+1);
s("Expand matching center",{
Array:[...a],Best:[b]
},[l,r]);
l--;
r++
}
}
return b
};

Execution canvas

Active Changed
STEP 1

Expand matching center

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

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

Worked example and algorithm walkthrough

Topic: Strings · Fundamentals and parsing

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

"cbbd"

Execution steps

  1. Expand matching center

Computed output

"bb"
JavaScript reference implementation
const solve = (a,s)=>{
  let b="";
  for(let i=0;
  i<a.length;
  i++)for(let d=0;
  d<2;
  d++){
    let l=i,r=i+d;
    while(l>=0&&r<a.length&&a[l]===a[r]){
      if(r-l+1>b.length)b=a.slice(l,r+1);
      s("Expand matching center",{
        Array:[...a],Best:[b]
      },[l,r]);
      l--;
      r++
    }
  }
  return b
};

Continue learning

Practice related DSA questions in the same topic.