It is guaranteed that there will be no two consecutive zeroes, and there will always be a zero at the beginning and end of the linked list.
The first line of input contains the elements of the singly linked list separated by a single space. The -1 indicates the end of the singly linked list and hence, would never be a list element.
The first and the only output line contains the integers present in the linked list after all the merging operations have been performed.
You do not need to print anything, it has already been taken care of. Just implement the given function.
3 <= N <= 10^5
0 <= VAL <= 10^3
Where 'VAL' represents the integers present in the list.
Time limit: 1 sec
Let us initialize two pointers, newHead and newTail, with NULL (These will be the head and tail of the final list). Now traverse the given list. Ignore the first zero. Now, as you encounter non-zero nodes, add their values in a variable called ‘sum’. As soon as you encounter a node with data 0, change that node's value to ‘sum’, and
Follow this algorithm for the rest of the list.
Note that we are not creating a new list, because we don’t create new nodes, we simply change the values of existing nodes and modify their connections.
Deletion In Doubly Linked List
Insertion In Doubly Linked List
LRU Cache
Delete Nodes On Regular Intervals
Add One To Linked List