C++ || Using Preorder Traversal || Explained
Intuition\nAs we know we need to find the sum between the ranges , so very first thing that comes in our mind is to check all the nodes one by one any try out..
# Intuition\nAs we know we need to find the sum between the ranges , so very first thing that comes in our mind is to check all the nodes one by one any try out.... (Using Recursion Do the Traversal)\n\n# Approach\n1. build a rescursive function to call check each node of BST\n2. if my node current value lies under the given ranges then I\'ll take that into my sum\n3. Contuniue calling recursively untill the tree is not finished\n4. Return the sum between ranges\n\n# Complexity\n- **Time complexity: O(n)**  -> here n is number of nodes\n\n- **Space complexity: O(n)**  -> stack space of recursion\n\n# Code\n```\nclass Solution {\npublic:\n    void find(TreeNode* root,int low,int high,int& sum)\n    {\n        if(root==NULL) return;\n\n        if(root->val >= low && root->val <= high) sum += root->val;\n\n        find(root->left,low,high,sum);\n        find(root->right,low,high,sum);\n    }\n    int rangeSumBST(TreeNode* root, int low, int high) \n    {\n        int sum = 0;\n        find(root,low,high,sum);\n        return sum;\n    }\n};\n```
['Tree', 'Depth-First Search', 'Binary Search Tree', 'Binary Tree', 'C++']