Practice Kth Largest Sum in a Binary Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Kth Largest Sum in a Binary Tree
Problem Statement
You are given the root of a binary tree and a positive integer k. The level sum in the tree is the sum of the values of the nodes that are on the same level. Return the kth largest level sum in the tree (not necessarily distinct). If there are fewer than k levels in the tree, return -1. Note that two nodes are on the same level if they have the same distance from the root.
Source: Kth Largest Sum in a Binary Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [5,8,9,2,1,3,7,4,6], k = 2
13
# Example 2
root = [1,2,null,3], k = 1
3
Constraints
Related LeetCode Problems
Practice more problems similar to Kth Largest Sum in a Binary Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.