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
Given a singly linked list with integers separated by '0', merge nodes between '0's into a single node with sum of included nodes.
Traverse the linked list and keep track of sum between zeroes
Merge nod...read more
Help your peers!
Add answer anonymously...
Top Travclan Technology India Technical Trainee interview questions & answers
Popular interview questions of Technical Trainee
>
Travclan Technology India Technical Trainee 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