15% off all plans & roadmaps Use code
See plansLeetCode 86 · Solution & editorial
Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
Partition List is a Linked List Manipulation Patterns problem, in the Reordering / Partitioning subpattern. The pattern covers in-place reversal, merging sorted lists, reordering, and intersection detection
Learn to reorder and partition linked lists. Master techniques like swap pairs, rotate list, and odd-even separation.
The reference solution runs in O(n) time and O(n) space.
Partition List has been reported in interviews at Microsoft, Amazon, Apple, Bloomberg, Facebook.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Partition List is a Linked List Manipulation Patterns problem, in the Reordering / Partitioning subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.