New update is available. Click here to update.

Last Updated: 23 Mar, 2021

Difficulty: Easy

```
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
```

SIMILAR PROBLEMS

Blueprint

Posted: 8 Sep, 2022

Difficulty: Moderate

Plantation

Posted: 9 Sep, 2022

Difficulty: Moderate

Capturing Grid

Posted: 14 Sep, 2022

Difficulty: Moderate

Rotting Oranges

Posted: 15 Sep, 2022

Difficulty: Moderate

Distance to a Cycle in Undirected Graph

Posted: 7 Nov, 2022

Difficulty: Moderate

Popular Interview Problems: