Workspace Single Number Iii
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Single Number III visualizer

Learn Single Number III with a step-by-step Bit Manipulation visualizer, JavaScript source code and a worked example. Practice bit operations.

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
[
  1,
  2,
  1,
  3,
  2,
  5
]

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let x=a.reduce((v,y)=>v^y,0),bit=x&-x,l=0,r=0;
for(let y of a){
if(y&bit)l^=y;
else r^=y;
s("Separate by differing bit",{
Mask:[bit],Groups:[l,r]
})
}
return [l,r].sort((a,b)=>a-b)
};

Execution canvas

Active Changed
STEP 1

Separate by differing bit

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

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

Worked example and algorithm walkthrough

Topic: Bit Manipulation · Bit operations

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

[
  1,
  2,
  1,
  3,
  2,
  5
]

Execution steps

  1. Separate by differing bit

Computed output

[
  3,
  5
]
JavaScript reference implementation
const solve = (a,s)=>{
  let x=a.reduce((v,y)=>v^y,0),bit=x&-x,l=0,r=0;
  for(let y of a){
    if(y&bit)l^=y;
    else r^=y;
    s("Separate by differing bit",{
      Mask:[bit],Groups:[l,r]
    })
  }
  return [l,r].sort((a,b)=>a-b)
};

Continue learning

Practice related DSA questions in the same topic.