filmov
tv
Leetcode: 2583 || Kth Largest Sum in a Binary Tree || @codewithanusha

Показать описание
Thanks for watching guys ! if you like it then please like and subscribe this channel 👍👍👍👍
😀😀😀😀
----------------------------------------------------------------------------------------------------------------------------------------
❓Question links:
🤔 C++ Solution:
___________________________________________________________________________________
Question
----------------------------------------------------------------------------------------------------------------------------------------
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 following:
- Level 1: 5.
- Level 2: 8 + 9 = 17.
- Level 3: 2 + 1 + 3 + 7 = 13.
- Level 4: 4 + 6 = 10.
The 2nd largest level sum is 13.
Example 2:
Input: root = [1,2,null,3], k = 1
Output: 3
Explanation: The largest level sum is 3.
________________________________________________________________
---------------------------------------------------------------------------------------------------------
Connect with me
________________________________________________________________
---------------------------------------------------------------------------------------------------------
# Tag #
___________________________________________________________________________________
----------------------------------------------------------------------------------------------------------------------------------------
#india #coding #hiring #experience #networking #interview #resume #like #projects #fresher #GeeksforGeeks
#gfg #GeeksforGeeks #code #coding #india #indian #coder #coderlife #sde #softwaredeveloper #softwareengineer #softwarecompany #competitiveprogramming #competitivecoding #leetocde #code #coding #india #indian #coder #coderlife #sde #softwaredeveloper #softwareengineer #softwarecompany #competitiveprogramming #competitivecoding #leetcode #leetcodeing #share
😀😀😀😀
----------------------------------------------------------------------------------------------------------------------------------------
❓Question links:
🤔 C++ Solution:
___________________________________________________________________________________
Question
----------------------------------------------------------------------------------------------------------------------------------------
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 following:
- Level 1: 5.
- Level 2: 8 + 9 = 17.
- Level 3: 2 + 1 + 3 + 7 = 13.
- Level 4: 4 + 6 = 10.
The 2nd largest level sum is 13.
Example 2:
Input: root = [1,2,null,3], k = 1
Output: 3
Explanation: The largest level sum is 3.
________________________________________________________________
---------------------------------------------------------------------------------------------------------
Connect with me
________________________________________________________________
---------------------------------------------------------------------------------------------------------
# Tag #
___________________________________________________________________________________
----------------------------------------------------------------------------------------------------------------------------------------
#india #coding #hiring #experience #networking #interview #resume #like #projects #fresher #GeeksforGeeks
#gfg #GeeksforGeeks #code #coding #india #indian #coder #coderlife #sde #softwaredeveloper #softwareengineer #softwarecompany #competitiveprogramming #competitivecoding #leetocde #code #coding #india #indian #coder #coderlife #sde #softwaredeveloper #softwareengineer #softwarecompany #competitiveprogramming #competitivecoding #leetcode #leetcodeing #share
Комментарии