Dsa
Binary Search Tree
Warm-up
Terminal Node Sum
In a decision tree model (represented as a BST), 'Terminal' nodes represent final outcomes. Given an insertion sequence for a BST, calculate the sum of all values stored in the terminal (leaf) nodes.
Input Format:
A single line of space-separated integers.
Output Format:
An integer representing the sum of all leaf node values.
Example:
Input:
10 5 15 3 7 12 18
Output:
40
(The leaves are 3, 7, 12, and 18. Their sum is 40.)
Key concepts
binary_search_treetraversalleaf_nodes
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now