Iterative and recursive - doesn't visit every node if possible
Complexity\n- Time complexity: O(N) - Number of nodes\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(H) - Height of the tree\n Add your sp
# Complexity\n- Time complexity: O(N) - Number of nodes\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(H) - Height of the tree\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Iterative\n```\npublic class Solution {\n    public int RangeSumBST(TreeNode root, int low, int high) {\n        var count = 0; // number of nodes that satisfy the condition\n        var queue = new Queue<TreeNode>(); // recursion representor\n        queue.Enqueue(root); // starting with root\n\n        while(queue.Count > 0) {\n            var current = queue.Dequeue(); // getting current node\n            if(current is null) continue; // leaf node - continue\n\n            if(current.val < low) {\n                // if current value is smaller than low boundary\n                // we shouldn\'t keep going left as those values MUST\n                // be smaller than low as well so we just go right\n                queue.Enqueue(current.right);\n            }\n            else if(current.val > high) {\n                // if current value is greater than high boundary\n                // we shouldn\'t keep going right as those values MUST\n                // be greater than high as well so we just go left \n                queue.Enqueue(current.left);\n            }\n            else {\n                // node value does fall in range \n                // so we add it to the sum\n                // now, we can keep going both left and right\n                // knowing that if current node does fall in range\n                // than both of it\'s children may fall \n                //in range as well\n                count += current.val;\n                queue.Enqueue(current.left);\n                queue.Enqueue(current.right);\n            }\n        }\n\n        return count;\n    }\n}\n```\n# Recursive\n```\npublic class Solution {\n    public int RangeSumBST(TreeNode root, int low, int high) {\n        int RangeSum(TreeNode current) {\n            // same goes here as explained for the iterative approach\n            if(current is null) return 0;\n\n            if(current.val < low) return RangeSum(current.right);\n            else if(current.val > high) return RangeSum(current.left);\n            return current.val + RangeSum(current.right) + RangeSum(current.left);\n        }\n\n        return RangeSum(root);\n    }\n}\n```
['C#']