Number Of Good Leaf Nodes Pairs
A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to ‘DISTANCE’.
The first line contains an Integer 'T' which denotes the number of test cases to be run. Then the test cases follow. The first line of each test case contains one integer ‘DISTANCE’, as described in the problem statement. The second line of each test case contains the elements of the tree in the level order form separated by a single space. If any node does not have a left or right child, take -1 in its place.
For each test case, print the number of good leaf node pairs in the tree. The output of every test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10 1 <= Number of Nodes in the tree,N <= 2^10 1 <= DISTANCE <= 10 1 <= Node value <= 10000 Time Limit: 1sec
Distance to a Cycle in Undirected Graph