Leaf under budget
Submissions: 3044   Accuracy:


  Difficulty: Easy   Marks: 2

Given a binary tree and a budget. Assume you are at the root of the tree(level 1), you need to maximise 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.

Input Format:
The function takes two arguments as input, the reference pointer to the root of the binary tree and a variable budget denoting the budget provided to you.
There will be T test cases and for each test case the function will be called separately.

Output Format:
For each test case output the total of number of the leaf nodes you can visit in the provided budget.

Your Task:
You don't need to read input/output. Just complete the function getCount that takes root node and budget as input.



10 8 L 8 3 L 10 2 R 2 3 L 3 4 R 2 6 R
TestCase 1:
Binary Tree is as:
                /       \
              8         2
            /         /       \
          3        3         6
Cost For visiting Leaf Node 3: 3(level)
Cost For visiting Leaf Node 4: 4(level)
Cost For visiting Leaf Node 6: 3(level)
In budget one can Max 2 Leaf Nodes.

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

** For More Input/Output Examples Use 'Expected Output' option **

Author: harshitsidhwa

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.