Print Nodes having K leaves
Submissions: 7130   Accuracy:

30.53%

  Difficulty: Medium   Marks: 4

Given a binary tree and a integer value K, the task is to print all nodes data in given binary tree having exactly K leaves in sub-tree rooted with them. If no node is found then print -1.

Input Format:
The first line of input  contains an integer T denoting the number of test cases. First line of each test case consists of two integers N and K. Second line of each test case consists of the struct Node, which has a data part which stores the data, pointer to left child and pointer to right child.

Output Format:
For each test case print the respective output in each line.

Your Task:
No need to read any input/output. Just complete the function btWithKleaves.

Constraints:
1 <= T <= 100
1 <= N <= 100
0 <= K <= 100
1 <= value of nodes <= 100

Example(To be used only for expected output):
Input:

2
2 1
0 1 L 0 2 R
4 2
0 1 L 0 2 R 2 3 R 2 4 L

Output:
-1
2

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

Contributor: Saksham Raj Seth
Author: saksham seth


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.