PROBLEM OF THE DAY: 02/09/2023 | Leaf under budget
source link: https://www.geeksforgeeks.org/videos/problem-of-the-day-02092023-leaf-under-budget/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
PROBLEM OF THE DAY: 02/09/2023
Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Self-balancing BST but will also help you build up problem-solving skills.
In this problem, we are given a binary tree and a budget. Assume you are at the root of the tree(level 1), we need to maximize the count of leaf nodes you can visit in your budget if the cost of visiting a leaf node is equal to the level of that leaf node.
Example :
Input:
10
/ \
8 2
/ / \
3 3 6
\
4
and budget = 8
Output: 2
Explanation:
Cost For visiting Leaf Node 3: 3
Cost For visiting Leaf Node 4: 4
Cost For visiting Leaf Node 6: 3
In budget 8 one can visit Max 2 Leaf Nodes.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK