MEDIUM NC#37 Blind #45 Linked List
143. Reorder List
๐ Problem
You are given the head of a singly linked-list. The list can be represented as: L0 โ L1 โ ... โ Ln-1 โ Ln Reorder the list to be on the following form: L0 โ Ln โ L1 โ Ln-1 โ L2 โ Ln-2 โ ... You may not modify the values in the list's nodes. Only nodes themselves may be changed.
๐ง Visual Learning Aid
1 Model the input into the right structure
2 Choose the core technique and invariant
3 Execute step-by-step with a sample
4 Validate complexity and edge cases
JS/TS Refreshers
- โขArray methods (`push`, `pop`, `shift`, `slice`)
- โขObject/Map/Set usage patterns
- โขFunction parameter and return typing
- โขMidpoint overflow-safe math
- โขLoop invariants
- โขMonotonic condition design
Logical Thinking Concepts
- โขDefine invariants before coding
- โขCheck edge cases first (`[]`, single element, duplicates)
- โขEstimate time/space before implementation
- โขApply Binary Search reasoning pattern
๐ก Approach
- โ Find middle of list using fast/slow pointers
- โ Reverse second half of list
- โ Merge first half and reversed second half alternately
- โ Time: O(n), Space: O(1)
๐งญ Prerequisites
๐ ๏ธ Hints & Pitfalls
Hints
- โขFind middle of list using fast/slow pointers
- โขReverse second half of list
- โขMerge first half and reversed second half alternately
Common Pitfalls
- โขTime: O(n), Space: O(1)
๐งช Test Cases
Test Case 1
Not run Input:
reorderList(list1); Expected:
null Test Case 2
Not run Input:
reorderList(list2); Expected:
null Test Case 3
Not run Input:
reorderList(head: ListNode | null); Expected:
Computed from hidden reference ๐ Code Editor
๐ค Output