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. You should preserve the original relative order of the nodes in each of the two partitions.
Example 1
Input: head = [1,4,3,2,5,2], x = 3
Output: [1,2,2,4,3,5]
Explanation: The nodes smaller than 3 are 1, 2 and 2, and they move to the front in their original order. The rest, 4, 3 and 5, follow in their original order.
Example 2
Input: head = [2,1], x = 2
Output: [1,2]
Explanation: 1 is smaller than x = 2, so it moves before 2.
Example 3
Input: head = [1,1,1], x = 2
Output: [1,1,1]
Explanation: Every node is smaller than 2, so the list stays the same.
Build two chains in a single pass — one for nodes less than x, one for the rest — appending each node to the correct chain in order. Then stitch the 'less' chain in front of the 'greater-or-equal' chain.
Run checks all cases above. Submit evaluates all test cases.