Input: 1 / \ 15 20 / \ / \ 3 5 4 2 \ / 2 3 Output: 2 Explanation: Children of 15 (3, 5) are factors of 15 Children of 20 (4, 2) are factors of 20 Input: 7 / \ 210 14 / \ \ 70 14 30 / \ / \ 2 5 10 15 / 23 Output:3 Explanation: Children of 210 (70, 14) are factors of 210 Children of 70 (2, 5) are factors of 70 Children of 30 (10, 15) are factors of 30
Approach: In order to solve this problem, we need to traverse the given Binary Tree in Level Order fashion and for every node with both children, check if both the children have values which are factors of the value of the current node. If true, then count such nodes and print it at the end.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of Nodes whose both immediate children are its prime factors
- Count of nodes in a Binary Tree whose immediate children are co-prime
- Node having maximum sum of immediate children and itself in n-ary tree
- Count of nodes in a Binary Tree whose child is its prime factors
- Check whether every node of binary tree has a value K on itself or its any immediate neighbours
- Count nodes with two children at level L in a Binary Tree
- Given a n-ary tree, count number of nodes which have more number of children than parents
- Find number of factors of N when location of its two factors whose product is N is given
- Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
- Number of full binary trees such that each node is product of its children
- Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
- Check for Children Sum Property in a Binary Tree
- Maximum parent children sum in Binary tree
- Iterative approach to check for children sum property in a Binary Tree
- Immediate Smaller element in an N-ary Tree
- Count the nodes of the tree which make a pangram when concatenated with the sub-tree nodes
- Convert a Binary Tree such that every node stores the sum of all nodes in its right subtree
- Create Balanced Binary Tree using its Leaf Nodes without using extra space
- Find root of the tree where children id sum for every node is given
- General Tree (Each node can have arbitrary number of children) Level Order Traversal
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.