
Asked in Walmart
Deepest Leaves Sum Problem Statement
Given a binary tree of integers, your task is to calculate the sum of all the leaf nodes present at the deepest level of this binary tree. If there are no such nodes, output 0.
Input:
The first line contains an integer 'T' denoting the number of test cases.
Each test case includes one line of elements in level order form, with node values separated by a single space. A null node is represented by -1.
Output:
For each test case, output the sum of all leaf nodes at the deepest level, printed on a new line.
Example:
Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
7
Explanation:
The binary tree represented by the input has depth levels as depicted in a given image, with the deepest leaves being [7], thus the sum is 7.
Constraints:
- 1 ≤ T ≤ 102
- 0 ≤ N ≤ 3000
- The sum is guaranteed to fit within a 32-bit integer.
- Time limit: 1 second.
Note:
You do not need to handle printing the output in your submission. Focus on implementing the function to solve the problem.

AnswerBot
4mo
Calculate the sum of leaf nodes at the deepest level of a binary tree.
Traverse the binary tree to find the deepest level of leaf nodes.
Sum the leaf nodes at the deepest level.
Handle null nodes represe...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Walmart
Q. Tell me about yourself.
Q. How many languages do you know?
Q. What are your strengths?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Walmart Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

