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)

๐Ÿ› ๏ธ 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

๐Ÿ“š Reference Solution

โ–ผ
โŒ˜K Search โŒ˜โ†ฉ Run โŒ˜S Submit