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!
Select
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?
Snapdeal Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits