Sum Between Zeroes Problem Statement
Given a singly linked list containing a series of integers separated by the integer '0', modify the list by merging nodes between two '0's into a single node. This merged node should store the sum of all included nodes.
Note:
There will be no consecutive zeroes, and the list will always start and end with a zero.
Input:
The linked list elements are provided on one line, separated by spaces. Use -1 to denote the end of the input and this should not be part of the list.
Output:
The output should contain the integers present in the linked list after all merging operations.
Example:
Input:
0 1 2 0 3 0 -1
Output:
0 3 0 3 0
Constraints:
3 ≤ N ≤ 10^5
0 ≤ VAL ≤ 10^3
- Time limit: 1 sec
Here, 'VAL' are the integers in the list.
AnswerBot
2d
Merge nodes between zeroes in a singly linked list to store the sum of included nodes.
Traverse the linked list and keep track of sum between zeroes
Merge nodes between zeroes by updating the sum in the...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