Workspace Letter Combinations Of A Phone Number
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Letter Combinations of a Phone Number visualizer

Learn Letter Combinations of a Phone Number with a step-by-step Recursion & Backtracking visualizer, JavaScript source code and a worked example. Practice subsets and combinations.

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

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let m=["","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"],o=[];
function f(i,p){
s("Choose letter",{
Digits:[...a],Path:[...p],Solutions:o
});
if(i===a.length){
o.push(p);
return
}
for(let x of m[+a[i]])f(i+1,p+x)
}
f(0,"");
return o
};

Execution canvas

Active Changed
STEP 1

Choose letter

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

Digits2 items
Path0 items

Empty at this step.

Solutions0 items

Empty at this step.

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

Worked example and algorithm walkthrough

Topic: Recursion & Backtracking · Subsets and combinations

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

"23"

Execution steps

  1. Choose letter

Computed output

[
  "ad",
  "ae",
  "af",
  "bd",
  "be",
  "bf",
  "cd",
  "ce",
  "cf"
]
JavaScript reference implementation
const solve = (a,s)=>{
  let m=["","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"],o=[];
  function f(i,p){
    s("Choose letter",{
      Digits:[...a],Path:[...p],Solutions:o
    });
    if(i===a.length){
      o.push(p);
      return
    }
    for(let x of m[+a[i]])f(i+1,p+x)
  }
  f(0,"");
  return o
};

Continue learning

Practice related DSA questions in the same topic.