# Count Subtrees

Easy
0/40
Average time to solve is 15m
Contributed by

## Problem statement

You have been given a Binary Search Tree (BST) of integer values and 2 integers 'LOW' and 'HIGH' denoting range ['LOW', 'HIGH'].

Your task is to return the count of nodes where all the nodes under that node (or subtree rooted with that node) lie in the given range.

A binary search tree (BST) is a binary tree data structure with the following properties.

``````â€¢ The left subtree of a node contains only nodes with data less than the nodeâ€™s data.

â€¢ The right subtree of a node contains only nodes with data greater than the nodeâ€™s data.

â€¢ Both the left and right subtrees must also be binary search trees.
``````
Example:
``````Consider the following binary search tree. Suppose the given range is [ 15, 32 ] so we return â€˜2â€™ as an answer as there are two nodes whose subtree is in the given range, the nodes are 20 and 30.
``````

Detailed explanation ( Input/output format, Notes, Images )
Constraints:
``````1 <= T <= 10
1 <= N <= 3*10^3
1 <= data <= 10^9 (data != -1)

Where 'N' denotes the number of nodes in the given BST and 'data' denotes the value of those nodes.

Time Limit: 1 sec
``````
##### Sample Input 1:
``````2
10 5 50 1 -1 40 100 -1 -1 -1 -1 -1 -1
5 45
10 5 50 1 -1 40 100 -1 -1 -1 -1 -1 -1
1 45
``````
##### Sample Output 1:
``````1
3
``````
##### Explanation For Sample Input1:
``````For the first test case :
As there is only 1 node (40) whose subtree is in the given range.

For the second test case :
As there are three nodes (1, 5, and 40) whose subtree is in the given range.
``````
##### Sample Input 2 :
``````2
10 5 50 -1 -1 -1 -1
20 25
10 5 50 -1 -1 -1 -1
1 25
``````
##### Sample Output 2:
``````0
1
``````
Console