Given a BST and a range a b count how many elements are insi
Given a BST and a range [a, b], count how many elements are inside that range.
Solution
#include <iostream>
 using namespace std;
struct node
 {
 int data;
 node *left;
 node *right;
 };
int countNodes(node *bst,int a,int b)
 {
 if(bst==NULL)
 return 0;
   
 if(bst->data>=a && bst->data<=b)
 return 1+countNodes(bst->left,a,b)+countNodes(bst->right,a,b);
 else
 return countNodes(bst->left,a,b)+countNodes(bst->right,a,b);
 }
int main() {
    // your code goes here
   return 0;
 }
![Given a BST and a range [a, b], count how many elements are inside that range.Solution#include <iostream> using namespace std; struct node { int data; nod Given a BST and a range [a, b], count how many elements are inside that range.Solution#include <iostream> using namespace std; struct node { int data; nod](/WebImages/3/given-a-bst-and-a-range-a-b-count-how-many-elements-are-insi-972594-1761499772-0.webp)
