← All problems

Reorder List

medium

Given the head of a linked list L0 → L1 → ... → Ln, reorder it in place to L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → ... and return the new head.

Find the middle with slow/fast pointers, reverse the second half, then merge the two halves node by node — three techniques you already have, chained together.

Example

Input: head = [1, 2, 3, 4]
Output: [1, 4, 2, 3]
Loading...