Question bank › Binary Search Tree
Dsa Binary Search Tree Medium

Subtree Weight Gap

For every node in a BST, define its 'Weight Gap' as the absolute difference between the sum of all node values in its left subtree and the sum of all node values in its right subtree. Find the value of the node that has the largest Weight Gap. If multiple nodes share the same maximum gap, return the node with the smallest value. Example: Input: 10 5 15 Node 5: LeftSum=0, RightSum=0, Gap=0 Node 15: LeftSum=0, RightSum=0, Gap=0 Node 10: LeftSum=5, RightSum=15, Gap=10 Largest gap is 10 at node 10. Output: 10

Key concepts

binary_search_treerecursionsubtree_analysis

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.