
Maximum Level Sum Problem Statement
Given a binary tree with integer nodes, your task is to determine the maximum level sum among all the levels in the binary tree. The sum at any level is the sum of all nodes that are present at that level.
Input:
The first line contains an integer 'T', representing the number of test cases. The subsequent lines for each test case provide the tree elements in level order format, with node values separated by a single space. Use -1 to represent null nodes.
Output:
Return a single integer for each test case that indicates the maximum level sum of the binary tree. The output for each test case should be printed on a new line.
Example:
Input:
1
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Output:
18
Explanation:
The binary tree is composed as follows:
- Level 1: Node = 1
- Level 2: Nodes = 2, 3
- Level 3: Nodes = 4, (null), 5, 6
- Level 4: Nodes = (null), 7, (null), (null), (null), (null)
- Level 5: Nodes = (null), (null)
The sums of each level are: Level 1 = 1, Level 2 = 5, Level 3 = 15, Level 4 = 7. The maximum sum is 18 at Level 3.
Constraints:
1 <= T <= 100
1 <= N <= 1000
, where N is the total number of nodes across all levels.-10^5 <= DATA <= 10^5
andDATA != -1
- All nodes are non-null availing the data constant.
- Time limit per test case is 1 second.
Note:
The input format example was illustrative. The actual input is a flat sequence of values in a single line, considering null (-1) for understanding parent-child assignments implicitly.


Find the maximum level sum in a binary tree with integer nodes.
Traverse the binary tree level by level and calculate the sum of nodes at each level.
Keep track of the maximum level sum encountered so f...read more

Top Housing.com Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Housing.com Software Developer
Reviews
Interviews
Salaries
Users/Month