Sum Between Zeroes
You are given a Singly Linked List which contains a series of integers separated by ‘0’.
Between two zeroes, you have to merge all the nodes lying between them into a single node which contains the sum of all the merged nodes. You have to perform this in place.
Note:
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.
Input Format:
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.
Output Format:
The first and the only output line contains the integers present in the linked list after all the merging operations have been performed.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
3 <= N <= 10^5
0 <= VAL <= 10^3
Where 'VAL' represents the integers present in the list.
Time limit: 1 sec
CodingNinjas
author
2y
Two Pointer Approach
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 ...read more
Help your peers!
Add answer anonymously...
Top Encore Capital Group Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Encore Capital Group Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app