Sum of Linked Lists Time : O(n + m) Space : O(n + m) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051using namespace std;// This is an input struct. Do not edit.class LinkedList {public: int value; LinkedList *next = nullptr; LinkedList(int value) { this->value = value; }};LinkedList *sumOfLinkedLists(LinkedList *linkedListOne, LinkedList *linkedListTwo) { int append = 0; LinkedList* dummy = new LinkedList(-1); LinkedList* tail = dummy; while(linkedListOne and linkedListTwo) { int sum = append + linkedListOne->value + linkedListTwo->value; linkedListOne = linkedListOne->next; linkedListTwo = linkedListTwo->next; append = sum / 10; sum = sum % 10; LinkedList* newTail = new LinkedList(sum); tail->next = newTail; tail = newTail; } while(linkedListOne) { int sum = append + linkedListOne->value; linkedListOne = linkedListOne->next; append = sum / 10; sum = sum % 10; LinkedList* newTail = new LinkedList(sum); tail->next = newTail; tail = newTail; } while(linkedListTwo) { int sum = append + linkedListTwo->value; linkedListTwo = linkedListTwo->next; append = sum / 10; sum = sum % 10; LinkedList* newTail = new LinkedList(sum); tail->next = newTail; tail = newTail; } if(append) { LinkedList* newTail = new LinkedList(append); tail->next = newTail; tail = newTail; } return dummy->next;}