Data Structures19 sections · 729 units
Open in Course

Reorder List Solution

Implement your solution

Implement the complete reorder in O(1)O(1) space.

Implementation details:

  • Be careful with the middle: for even lengths, you want the first half to be one node longer
  • After reversing, second points to the new head of the reversed half
  • In the merge phase, save next pointers before overwriting

This problem is a checkpoint.

If you can solve it cleanly, you've internalized the core linked list techniques. Test on: even length, odd length, two nodes, single node. Time: O(n)O(n). Space: O(1)O(1).