Calculate sum of root to leaf digits in a binary tree
Given a binary tree, where each node stores a value between 0 and 9, calculate the sum of the numbers created by the paths from root to leaf.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a binary tree, where each node stores a value between 0 and 9, calculate the sum of the numbers created by the paths from root to leaf.
Given a binary tree and an integer k, count the total number of paths in the tree whose sum of all nodes is equal to k.
Given the root of a binary tree, determine if the binary tree holds children-sum property. For a tree to satisfy the children-sum property, each node’s value should be equal to the sum of values at its left and right node.
Given a linked list, construct a complete binary tree from it. Assume that the order of elements present in the linked list is the same as that in the complete tree’s array representation.
Given a binary tree, check if removing an edge can split it into two binary trees of equal size.
Given an array representing the parent-child relationship in a binary tree, find the tree’s height without building it. The parent-child relationship is defined by (A[i], i) for every index i in array A.
Given a binary tree and two tree pointers, x and y, write an efficient algorithm to check if they lie on the same root-to-leaf path in the binary tree. In other words, determine whether x is an ancestor of y, or x is a descendant of y.
An independent set is a set of nodes in a binary tree, no two of which are adjacent. The maximum independent set problem is finding an independent set of the largest possible size for a given binary tree.
Evaluate a given binary expression tree representing algebraic expressions. A binary expression tree is a binary tree, where the operators are stored in the tree’s internal nodes, and the leaves contain constants.
Given a binary tree, check if each node has exactly one child or not. In other words, check whether the binary tree is skewed or not.
Given a binary tree, perform the boundary traversal of it. The solution should print the boundary nodes starting from the root of the tree, in an anti-clockwise direction, without any duplicates.
Write an efficient algorithm to fix the children-sum property in a given binary tree. The only operation allowed is an increment operation on the node’s value.