Maximum Level Sum in Binary Tree Problem Statement
Given an arbitrary binary tree consisting of N nodes, where each node is associated with a certain value, your task is to find the maximum sum for any level in the tree.
Example:
Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
13
Explanation:
The maximum level sum is 13 for level 3 from node values (5+6+2) or level 1 (17-4).
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 3000
-1000 ≤ data ≤ 1000
- data ≠ -1
Note:
- The input for a tree is provided as a single line of integers separated by spaces, representing level order traversal where '-1' denotes a null node.

AnswerBot
4mo
Find the maximum sum for any level in a binary tree.
Traverse the binary tree level by level and calculate the sum for each level.
Keep track of the maximum sum encountered so far.
Return the maximum sum...read more
Help your peers!
Add answer anonymously...
Snapdeal Software Engineer interview questions & answers
A Software Engineer was asked Q. Given an array, find a pair of elements.
A Software Engineer was asked Q. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q. How many rectangles/squares are there on a chessboard?
Popular interview questions of Software Engineer
A Software Engineer was asked Q1. Given an array, find a pair of elements.
A Software Engineer was asked Q2. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q3. How many rectangles/squares are there on a chessboard?
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

