Odd Even Linked List – Solution & Complexity
Solution Walkthrough
Step 1: Recognize the Pattern
The key pattern is: walk two interleaved chains (odd and even) simultaneously with a single pass, splicing each node onto its own chain as you go, then reattach the even chain after the odd chain's tail.
Step 2: Build the Algorithm
Advance one state transition at a time. Mark or update state before exploring dependent work.
Step 3: Check Edge Cases
Test empty or minimal input, skewed shapes, duplicates where allowed, and impossible outcomes.
Step 4: Solution and Complexity
Time: O(n) — a single pass over the list. Space: O(1) — only a constant number of pointers are used; the existing nodes are relinked in place, not copied.
All 5 languages below run and submit against the remote judge for this problem — Java/Go/Rust use the same real ListNode structural-type support the judge added for the rest of the linked-list track.