Rearrange Linked List Time : O(n) Space : O(1) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546using namespace std;class LinkedList {public: int value; LinkedList *next; LinkedList(int value) { this->value = value; next = nullptr; }};LinkedList *rearrangeLinkedList(LinkedList *head, int k) { LinkedList *smallerDummy = new LinkedList(-1), *smallerTail = smallerDummy; LinkedList *biggerDummy = new LinkedList(-1), *biggerTail = biggerDummy; LinkedList *kDummy = new LinkedList(-1), *kTail = kDummy; while(head) { LinkedList* nxt = head->next; head->next = nullptr; if(head->value < k) { smallerTail->next = head; smallerTail = smallerTail->next; } else if(head->value == k) { kTail->next = head; kTail = kTail->next; } else { biggerTail->next = head; biggerTail = biggerTail->next; } head = nxt; } LinkedList* tail = smallerTail; if(kDummy != kTail) { tail->next = kDummy->next; tail = kTail; } if(biggerDummy != biggerTail) { tail->next = biggerDummy->next; } return smallerDummy->next;}