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.
x = 3Output:1->2->2->3->3->4->5Explanation: Nodes with value less than 3 come first, then equal to 3 and then greater than 3.
Input:1->4->2->10 x = 3Output: 1->2->4->10Explanation: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.