You have been given a Linked List of 'N' nodes such that each node represents a single digit.
Note:
1. When 'N' is odd consider the middle element to be part of 1st half.
2. The sum should not contain any leading zero, except the number 0 itself.
For example:
Given a Linked List: 1-2-3-4-5-5-6
First half: 1-2-3-4
Reversed second half: 6-5-5
Output linkedlist: 1-8-8-9 = (1234 + 655 = 1889)
Follow Up:
Can you add both halves without finding the length of LinkedList and in O(1) space?
A single line of input contains the elements of the singly linked list separated by a single space and terminated by -1.
For each input, print a single line containing a string denoting the required sum.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
Constraints :
0 <= 'N' <= 10 ^ 5
0 <= 'DATA' <= 9
Where 'N' is the number of nodes in linked list and 'DATA' is the integer value in each node.
Time Limit: 1 sec