Workspace Word Break
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Word Break visualizer

Learn Word Break 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 / 9Execution step
Reference example · JavaScript
Inspect reference input
{
  "a": "leetcode",
  "dict": [
    "leet",
    "code"
  ]
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
a,dict
},s)=>{
let d=Array(a.length+1).fill(false);
d[0]=true;
for(let i=1;
i<=a.length;
i++){
d[i]=dict.some(w=>i>=w.length&&d[i-w.length]&&a.slice(i-w.length,i)===w);
s("Test dictionary suffix",{
Text:[...a],DP:d
},[i])
}
return d.at(-1)
};

Execution canvas

Active Changed
STEP 1

Test dictionary suffix

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

Text8 items
DP9 items
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

{
  "a": "leetcode",
  "dict": [
    "leet",
    "code"
  ]
}

Execution steps

  1. Test dictionary suffix

Computed output

true
JavaScript reference implementation
const solve = ({
  a,dict
},s)=>{
  let d=Array(a.length+1).fill(false);
  d[0]=true;
  for(let i=1;
  i<=a.length;
  i++){
    d[i]=dict.some(w=>i>=w.length&&d[i-w.length]&&a.slice(i-w.length,i)===w);
    s("Test dictionary suffix",{
      Text:[...a],DP:d
    },[i])
  }
  return d.at(-1)
};

Continue learning

Practice related DSA questions in the same topic.