Problem Statement: You are given a root node, you need to calculate the vertical sum of the tree. Consider the image below Vertical-Line-1: has only one node 7 => vertical sum is 7 Vertical-Line-2: has only one node 10 => vertical sum is 10 Vertical-Line-3: has …
Question: Given a binary tree root node, check if the tree is a isomorphic tree. 2 trees are called isomorphic to each other, if they have same structure or mirror structure. And their data should also match. Solution in C++ #include <iostream> #include <queue> #include <stack> …
Question: Given a binary tree root node, check if the tree is a foldable tree. Example: Consider the image given below We can see that, the nodes of left and right Subtree are exact mirror of each other. So we can solve this problem by using …
Problem Statement: Given a binary tree root node, you need to find the minimum and maximum value of the nodes. Consider the image below: Minimum value is 7 and maximum value is 30. Solution: We can solve this problem by traversing the tree and checking the …
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 …