Workspace Odd Even Linked List
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Odd Even Linked List visualizer

Learn Odd Even Linked List with a step-by-step Linked Lists visualizer, JavaScript source code and a worked example. Practice rewiring and advanced.

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 / 6Execution step
Reference example · JavaScript
Inspect reference input
[
  1,
  2,
  3,
  4,
  5
]

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
let odd=[],even=[];
a.forEach((x,i)=>{
(i%2?even:odd).push(x);
s("Append to positional chain",{
Odd:odd,Even:even
})
});
return odd.concat(even)
};

Execution canvas

Active Changed
STEP 1

Append to positional chain

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

Odd1 items
Even0 items

Empty at this step.

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

Worked example and algorithm walkthrough

Topic: Linked Lists · Rewiring and advanced

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,
  3,
  4,
  5
]

Execution steps

  1. Append to positional chain

Computed output

[
  1,
  3,
  5,
  2,
  4
]
JavaScript reference implementation
const solve = (a,s)=>{
  let odd=[],even=[];
  a.forEach((x,i)=>{
    (i%2?even:odd).push(x);
    s("Append to positional chain",{
      Odd:odd,Even:even
    })
  });
  return odd.concat(even)
};

Continue learning

Practice related DSA questions in the same topic.