Given a binary tree with root node pointer **A** and an integer **B**.

A complete path is defined as a path from the root to a leaf.

The sum of all nodes on that path is defined as the sum of that path.

You have to remove (prune the tree) all nodes which don’t lie in any path with sum >= B.

**Note**: A node can be part of multiple paths.

So we have to delete it only in case when all paths from it have sum less than B.

**Input Format**

```
The arguments given are root pointer A and an integer B.
```

**Output Format**

```
Return the root pointer after prunung the tree.
```

**Constraints**

```
1 <= Total number of nodos <= 100000
1 < = Nodes values <= 1000
1 <= B <= 10^9
```

**For Example**

```
Input 1:
1
/ \
2 3
/ \ \
3 4 5
B = 7
Output 1:
1
/ \
2 3
\ \
4 5
```

NOTE:You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.

Sign Up

to access hints and editorial solutions for**Remove nodes from Path sum less than B**

to access hints and editorial solutions for

Loading...