Workspace Number Of Substrings Containing All Three Characters
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Number of Substrings Containing All Three Characters visualizer

Learn Number of Substrings Containing All Three Characters with a step-by-step Sliding Window & Two Pointers visualizer, JavaScript source code and a worked example. Practice fixed and variable windows.

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
"abcabc"

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let p=[-1,-1,-1],c=0;
for(let i=0;
i<a.length;
i++){
p[a.charCodeAt(i)-97]=i;
c+=Math.min(...p)+1;
s("Count valid start positions",{
Array:[...a],LastSeen:p,Count:[c]
},[i])
}
return c
};

Execution canvas

Active Changed
STEP 1

Count valid start positions

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

Array6 items
LastSeen3 items
Count1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Sliding Window & Two Pointers · Fixed and variable windows

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

"abcabc"

Execution steps

  1. Count valid start positions

Computed output

10
JavaScript reference implementation
const solve = (a,s)=>{
  let p=[-1,-1,-1],c=0;
  for(let i=0;
  i<a.length;
  i++){
    p[a.charCodeAt(i)-97]=i;
    c+=Math.min(...p)+1;
    s("Count valid start positions",{
      Array:[...a],LastSeen:p,Count:[c]
    },[i])
  }
  return c
};

Continue learning

Practice related DSA questions in the same topic.