Dsa
Binary Search Tree
Medium
The Divisor Path Score
You are given a sequence of unique integers to be inserted into a Binary Search Tree (BST) in the order provided, without balancing. A node is considered a 'Kinship Node' if its value is a divisor of its parent node's value. Your task is to calculate the sum of all Kinship Nodes in the tree.
Example:
Input: 10 5 15 2 3 12 20
1. Insert 10 (root).
2. Insert 5 (left of 10). 10 % 5 == 0, so 5 is a Kinship Node.
3. Insert 15 (right of 10). 10 % 15 != 0.
4. Insert 2 (left of 5). 5 % 2 != 0.
5. Insert 3 (right of 5). 5 % 3 != 0.
6. Insert 12 (left of 15). 15 % 12 != 0.
7. Insert 20 (right of 15). 15 % 20 != 0.
Output: 5
Key concepts
binary_search_treetree_traversalparent_tracking
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