Problem Statement: Given a binary tree root node, you need to find the sum of all the leaf nodes. Consider the image below: The leaf nodes are 7, 15, 18, 30. So the sum is 70. We can solve this problem by checking if the node …

Question: Given a binary tree root node, get the average of all nodes in Binary Tree Solution: The sum of all the nodes is 121 Total number of nodes are :7 So the average is 121/7 = 17.2 Solution in C++ #include <iostream> #include <queue> …

Question: Given a binary tree root node, get the sum of the values of all the nodes formed from root to the leaf node. Solution: From the above image, we have 4 leaf nodes i.e : 3, 4, 6, 7 So the paths will be 1 …

Question: Given a binary tree root node and 2 node value, check if those 2 nodes are siblings. Solution: If we send the node value as 7 and 15, they are siblings If we send the node value as 7 and 18 they are not siblings. …

Question: Given a binary tree root node and a node value, get the sibling of that node. Solution: If the input node value is 10, its sibling is 25 If the input node value is 7, its sibling is 15 If the input node value is …

Question: Given a binary tree root node, check if it is a Binary Search Tree Solution: A Binary Tree is a BST if it satisfy below 2 conditions. The node values left of the root node should always be less and The node values right of …

Question: Given a binary tree node and root node, get the parent node of that node. Solution: Solution is very simple. Before we go to the child node of any parent node, we check if the children nodes is equal to given value. If it is …

Question: Given a binary tree root node, check if all Leaf Nodes are at same level in Binary tree Solution: We can solve this question with the help of pre-order traversal. First we visit the left leaf and update the level value, and then check with …

Question: Given a binary tree root node, check if the tree is a height balanced tree. What is a height balanced tree? A tree is called as height balanced tree if the difference between left height and right height should not be more than 1. It …

Question: Given a binary tree root node and 2 level, print the nodes between those levels. Example: Consider the image given below If given level is 2 and 3 the nodes that should be printed are: 10, 25, 7, 15, 18, 30 Solution: We do this …