Practice Reorder List
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
For a singly linked list L0 -> L1 -> ... -> Ln, rearrange its nodes into L0 -> Ln -> L1 -> L(n-1) -> L2 -> L(n-2) -> ... . Change next pointers only; do not replace node values. Update the original list. Practice approach: Find the midpoint with slow and fast pointers, disconnect and reverse the second half, then weave the two halves together. Terminate the final next pointer to avoid a cycle. This uses O(n) time and O(1) extra space.
Source: Reorder List on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
head = [1,2,3,4]
[1,4,2,3]
# Example 2
head = [1,2,3,4,5]
[1,5,2,4,3]
Constraints
Related LeetCode Problems
Practice more problems similar to Reorder List.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.