The Partition List problem asks you to rearrange a linked list such that all nodes with values less than x come before nodes with values ≥ x, while preserving the original relative order within each group. This Partition List coding problem uses the two-pointer split-and-merge technique. The linked list and two pointers interview pattern is directly demonstrated.
Apple, Microsoft, Meta, Amazon, Google, Bloomberg, and Adobe ask this because it tests stable linked list partitioning with two separate lists. It's analogous to the stable partition of an array but applied to linked lists, requiring careful pointer manipulation.
Two dummy heads + merge. Create two dummy nodes: lessHead and greaterHead. Scan the original list: if node.val < x, append to less list; otherwise append to greater list. Connect the two lists: lessHead_tail.next = greaterHead.next. Return lessHead.next.
list=1→4→3→2→5→2, x=3. (values < 3 go before, ≥ 3 go after) Less list: 1→2→2. Greater list: 4→3→5. Merge: 1→2→2→4→3→5. Result: 1→2→2→4→3→5.
next to null (creates a cycle).< x, not <= x.Partition List uses the "dual dummy head" pattern — the cleanest approach for list partitioning. Create dummy nodes for each group, append to appropriate group, then connect. Always null-terminate the last group. This pattern extends to "k-way list partition" and "group by property" linked list problems. The dummy node trick eliminates edge cases for empty groups.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Delete the Middle Node of a Linked List | Medium | Solve | |
| Swapping Nodes in a Linked List | Medium | Solve | |
| Rotate List | Medium | Solve | |
| Remove Duplicates from Sorted List II | Medium | Solve | |
| Remove Nth Node From End of List | Medium | Solve |