Tap here to switch tabs
Problem
Submissions

Problem: Maximum Level Sum of a Binary Tree

Maximum Level Sum of a Binary Tree finds the smallest level whose nodes have the greatest total value, even when the tree contains negative and positive values.

Statement

Given the root of a binary tree, the root is located at level 11, its children are located at level 22, and subsequent generations continue incrementally.

Return the smallest level xx such that the sum of all node values at level xx is maximal.

Constraints:

  • The number of nodes in the tree is in the range [1,104][1, 10^4].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Level Sum of a Binary Tree

Maximum Level Sum of a Binary Tree finds the smallest level whose nodes have the greatest total value, even when the tree contains negative and positive values.

Statement

Given the root of a binary tree, the root is located at level 11, its children are located at level 22, and subsequent generations continue incrementally.

Return the smallest level xx such that the sum of all node values at level xx is maximal.

Constraints:

  • The number of nodes in the tree is in the range [1,104][1, 10^4].

  • −105≤-10^5 \leq Node.val ≤105\leq 10^5