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.
Be the first one to answer
Add answer anonymously...
Snapdeal Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter