Tap here to switch tabs
Problem
Submissions

Problem: Kth Largest Sum in a Binary Tree

Kth Largest Sum in a Binary Tree finds the kth largest sum among all tree levels, treating equal sums as separate levels. Return negative one if the tree has fewer than k levels.

Statement

Given the root of a binary tree and a positive integer k, determine the kextthk^{ ext{th}} largest level sum in the tree.

The level sum of a binary tree is defined as the sum of all node values present at the same level.

Return the kextthk^{ ext{th}} largest level sum. If the binary tree contains fewer than k levels, return −1-1. Two levels having identical sums are treated as distinct values.

Constraints:

  • The number of nodes in the tree is n.

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq Node.val ≤106\leq 10^6

  • 1≤1 \leq k ≤\leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Kth Largest Sum in a Binary Tree

Kth Largest Sum in a Binary Tree finds the kth largest sum among all tree levels, treating equal sums as separate levels. Return negative one if the tree has fewer than k levels.

Statement

Given the root of a binary tree and a positive integer k, determine the kextthk^{ ext{th}} largest level sum in the tree.

The level sum of a binary tree is defined as the sum of all node values present at the same level.

Return the kextthk^{ ext{th}} largest level sum. If the binary tree contains fewer than k levels, return −1-1. Two levels having identical sums are treated as distinct values.

Constraints:

  • The number of nodes in the tree is n.

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq Node.val ≤106\leq 10^6

  • 1≤1 \leq k ≤\leq n