Workspace Repeated String Match
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Repeated String Match visualizer

Learn Repeated String Match with a step-by-step Strings visualizer, JavaScript source code and a worked example. Practice pattern matching.

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 / 4Execution step
Reference example · JavaScript
Inspect reference input
{
  "a": "abcd",
  "b": "cdabcdab"
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
a,b
},s)=>{
let v="",n=0;
while(v.length<b.length+a.length){
v+=a;
n++;
s("Append repeat",{
Text:[...v],Pattern:[...b],Repeats:[n]
});
if(v.includes(b))return n
}
return -1
};

Execution canvas

Active Changed
STEP 1

Append repeat

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

Text4 items
Pattern8 items
Repeats1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Strings · Pattern matching

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

{
  "a": "abcd",
  "b": "cdabcdab"
}

Execution steps

  1. Append repeat

Computed output

3
JavaScript reference implementation
const solve = ({
  a,b
},s)=>{
  let v="",n=0;
  while(v.length<b.length+a.length){
    v+=a;
    n++;
    s("Append repeat",{
      Text:[...v],Pattern:[...b],Repeats:[n]
    });
    if(v.includes(b))return n
  }
  return -1
};

Continue learning

Practice related DSA questions in the same topic.