BETA
Leaf under budget
Submissions: 726   Accuracy:

33.47%

  Difficulty: Easy
     

Given a binary tree and a budget. Assume you are at the root of the tree, you need to maximise the count of leaf nodes you can visit in your budget if you have to pay particular cost every time you visit a new node in the Tree ( you have to pay cost to visit leaf node also). Your task is to complete the function getCount().

Input:
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:
For each test case output the total of number of the leaf nodes you can visit in the provided budget.

Constraints:
1<=T<=100
1<=N<=100
1<=budget<=100

Example:
Input:

1
6
10 8 L 8 3 L 10 2 R 2 3 L 3 4 R 2 6 R
8
Output:
2
Explanation:
TestCase 1:
Binary Tree is as:
                  10
                /       \
              8         2
            /         /       \
          3        3         6
                       \
                        4  
Cost For visiting Leaf Node 3: 3
Cost For visiting Leaf Node 4: 4
Cost For visiting Leaf Node 6: 3
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


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