AMCAT Automata Fix Sample Question-7

Program-7

Binary Search Tree

Count the number of nodes in the BST that lie in the given range. In The existing function.

The values smaller than root go to the left side

The values greater and equal to the root go to the right side

1 comments on “AMCAT Automata Fix Sample Question-7”


  • yash.22311523

    void inorder(Node *root, int &cnt, int l, int h) {
    if (!root) return; // base case: empty tree

    // Traverse left subtree
    inorder(root->left, cnt, l, h);

    // Check current node
    if (root->data >= l && root->data right, cnt, l, h);
    }

    int getCount(Node *root, int l, int h) {
    int cnt = 0;
    inorder(root, cnt, l, h);
    return cnt;
    }