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

Single Number II visualizer

Learn Single Number II 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 / 5Execution step
Reference example · JavaScript
Inspect reference input
[
  2,
  2,
  3,
  2
]

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let v=0;
for(let i=0;
i<4;
i++){
let c=a.reduce((n,x)=>n+((x>>i)&1),0);
if(c%3)v|=1<<i;
s("Count bit modulo three",{
Bit:[i],Count:[c],Result:[v]
})
}
return v
};

Execution canvas

Active Changed
STEP 1

Count bit modulo three

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

Bit1 items
Count1 items
Result1 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

[
  2,
  2,
  3,
  2
]

Execution steps

  1. Count bit modulo three

Computed output

3
JavaScript reference implementation
const solve = (a,s)=>{
  let v=0;
  for(let i=0;
  i<4;
  i++){
    let c=a.reduce((n,x)=>n+((x>>i)&1),0);
    if(c%3)v|=1<<i;
    s("Count bit modulo three",{
      Bit:[i],Count:[c],Result:[v]
    })
  }
  return v
};

Continue learning

Practice related DSA questions in the same topic.