Set next pointer to the inorder successor of all nodes in a binary tree
Given a binary tree where each node has one extra pointer next, set it to the inorder successor for all binary tree nodes.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a binary tree where each node has one extra pointer next, set it to the inorder successor for all binary tree nodes.
Given a binary tree, efficiently print all nodes between two given levels in a binary tree. The nodes for any level should be printed from left to right.
Given a binary tree, calculate the difference between the sum of all nodes present at odd levels and the sum of all nodes present at even level.
Given a binary tree, print its nodes in vertical order. Assume that the left and right child of a node makes a 45–degree angle with the parent.
Given a binary tree, write an efficient algorithm to link nodes at the same level in the form of a linked list like structure.
This post will implement a treap data structure, a combination of a binary search tree and a heap, and perform basic operations like insert, search, and delete on it.
Write an efficient algorithm to find a binary tree’s preorder traversal from its inorder and postorder sequence without constructing the tree.
Given a binary tree, count all subtrees in it such that every node in the subtree has the same value.
Given a BST, find the inorder successor of a given key in it. If the given key does not lie in the BST, then return the next greater key (if any) present in the BST.
Given a binary tree, write an efficient algorithm to find the maximum sum path between any two leaves in it.
Given a binary tree, write an efficient algorithm to find all nodes present at a given distance from any leaf node. We need to find only those nodes that are present in the root-to-leaf path for that leaf.
Given a binary tree that is only one swap away from becoming a BST, convert it into a BST in a single traversal.