18. Sum of leaf nodes in BST
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
If the root is null, it returns 0.
If the root has no left and right children (i.e., it's a leaf node), it returns the value of that node.
Otherwise, it recursively calls itself on the left and right subtrees and returns the sum of the results.
Time Complexity : O(N)
, where N
is the number of nodes in the Binary Search Tree.
Auxiliary Space Complexity : O(H)
, where H
is the height of the Binary Search Tree.
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.