Find the vertical sum of a binary tree
Given a binary tree, the print vertical sum of it. Assume the left and right child of a node makes a 45–degree angle with the parent.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a binary tree, the print vertical sum of it. Assume the left and right child of a node makes a 45–degree angle with the parent.
Given a binary tree, determine the distance between given pairs of nodes in it. The distance between two nodes is defined as the total number of edges in the shortest path from one node and another.
Given a binary tree, find all ancestors of a given node in it.
Given a binary tree, write an efficient algorithm to print all paths from the root node to every leaf node in it.
Given a binary tree and two nodes, x and y, find the lowest common ancestor (LCA) of x and y in it. The lowest common ancestor (LCA) of two nodes x and y in a binary tree is the lowest (i.e., deepest) node that has both x and y as descendants, where each node can be a descendant of itself.
Given a binary tree, write an iterative and recursive solution to traverse the tree using inorder traversal in C++, Java, and Python.
Given a binary tree, write an iterative and recursive solution to traverse the tree using preorder traversal in C++, Java, and Python.
Given a binary tree, write an iterative and recursive solution to traverse the tree using postorder traversal in C++, Java, and Python.
Given a binary tree, write an efficient algorithm to determine if it can be converted into another binary tree by doing any number of swaps of its right and left branches.
Given a binary tree, write an efficient algorithm to convert the binary tree to its mirror.
Given a binary tree, write an efficient algorithm to check if it has a symmetric structure or not, i.e., left and right subtree mirror each other.
Given a binary tree, write an efficient algorithm to compute the diameter of it. Binary tree diameter equals the total number of nodes on the longest path between any two leaves in it.