Question bank › Binary Search Tree
Dsa Binary Search Tree Medium

Zig-Zag Path Factor

Build a BST from a sequence of integers. For every leaf node, calculate its 'Path Factor'. Path Factor calculation: Start at the root with 0. For each step down the path to the leaf: - If you move to a LEFT child at depth D, add (D * child_value) to the factor. - If you move to a RIGHT child at depth D, subtract (D * child_value) from the factor. (Root is depth 0). Find the sum of Path Factors for all leaf nodes in the tree. Example: Input: 10 5 15 Leaf 5: Depth 1, Left child. Factor = 0 + (1 * 5) = 5. Leaf 15: Depth 1, Right child. Factor = 0 - (1 * 15) = -15. Total sum: 5 + (-15) = -10. Output: -10

Key concepts

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