Workspace Isomorphic Strings
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Isomorphic Strings visualizer

Learn Isomorphic Strings 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 / 4Execution step
Reference example · JavaScript
Inspect reference input
{
  "a": "egg",
  "b": "add"
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
a,b
},s)=>{
let m=new Map,n=new Map;
for(let i=0;
i<a.length;
i++){
let x=a[i],y=b[i];
s("Check bijection",{
A:[...a],B:[...b],Mapping:[...m].map(p=>p.join("→"))
},[i]);
if(m.has(x)&&m.get(x)!==y||n.has(y)&&n.get(y)!==x)return false;
m.set(x,y);
n.set(y,x)
}
return true
};

Execution canvas

Active Changed
STEP 1

Check bijection

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

A3 items
B3 items
Mapping0 items

Empty at this step.

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

{
  "a": "egg",
  "b": "add"
}

Execution steps

  1. Check bijection

Computed output

true
JavaScript reference implementation
const solve = ({
  a,b
},s)=>{
  let m=new Map,n=new Map;
  for(let i=0;
  i<a.length;
  i++){
    let x=a[i],y=b[i];
    s("Check bijection",{
      A:[...a],B:[...b],Mapping:[...m].map(p=>p.join("→"))
    },[i]);
    if(m.has(x)&&m.get(x)!==y||n.has(y)&&n.get(y)!==x)return false;
    m.set(x,y);
    n.set(y,x)
  }
  return true
};

Continue learning

Practice related DSA questions in the same topic.