Kth Largest Sum In Binary Tree: Efficient BFS Solution
Find kth largest level sum in binary tree using BFS and sorting.
2583. Kth Largest Sum in a Binary Tree Difficulty: Medium Topics: Tree, Breadth-First Search, Sorting, Binary Tree 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. Example 1: Input: root = [5,8,9,2,1,3,7,4,6], k = 2 Output: 13 Explanation: The level sums are the followin...