 Partition a Linked List around a given value
Medium Accuracy: 71.04% Submissions: 4174 Points: 4

Given a linked list and a value x, partition it such that all nodes less than x come first, then all nodes with value equal to x and finally nodes with value greater than or equal to x. The original relative order of the nodes in each of the three partitions should be preserved. The partition must work in-place.

Example 1:
Input:
1->4->3->2->5->2->3,
x = 3
Output:
1->2->2->3->3->4->5
Explanation:
Nodes with value less than 3 come first,
then equal to 3 and then greater than 3.

Example 2:
Input:
1->4->2->10
x = 3
Output:
1->2->4->10
Explanation:
Nodes with value less than 3 come first,
then equal to 3 and then greater than 3.

You don't need to read input or print anything. Your task is to complete the function partition() which takes the head of the inked list and an integer x as input, and returns the head of the modified linked list after arranging the values according to x.

Expected time complexity : O(n)
Expected Auxiliary Space: O(n)

Constraints:
1 <= N <= 105
1 <= k <= 105

We are replacing the old Disqus forum with the new Discussions section given below.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  