c++
Maximum Path Sum in a Binary Tree
Given a binary tree, write an efficient algorithm to find the maximum path sum between any two nodes in it. The path can start and end at any node in the tree and need not Read more…
Given a binary tree, write an efficient algorithm to find the maximum path sum between any two nodes in it. The path can start and end at any node in the tree and need not Read more…
Construct an expression tree from a given postfix notation and print the infix notation. The binary expression tree is a binary tree whose leaves are operands, such as constants or variable names, and the other Read more…
Given a circularly sorted array of integers, find a pair with a given sum. Assume there are no duplicates in the array, and the rotation is in an anti-clockwise direction around an unknown pivot. For Read more…
Given two binary trees, check whether the leaf traversals of both trees are the same or not. For example, the leaf traversals of the following binary trees are 4, 5, 6. A simple solution is Read more…
Given two linked lists, where the tail of the second list points to a node in the first list, find the node where both lists intersect. Consider the following linked lists where the second list’s Read more…
Given n ropes of different lengths, connect them into a single rope with minimum cost. Assume that the cost to connect two ropes is the same as the sum of their lengths. For example, The Read more…
Given a level order representation of a complete binary search tree, print its elements in increasing order. For example, the level order representation of the complete BST below is [15, 10, 20, 8, 12, 18, Read more…
Given an array of words where no word is the prefix of another, find the shortest unique prefix to identify each word in the array uniquely. For example, The idea is to construct a Trie Read more…
Given a binary tree, extract all its leaves into a doubly linked list, i.e., remove all leaf nodes from the binary tree and construct a doubly linked list out of them. The extraction should be Read more…
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 For a tree to satisfy the children-sum property, each Read more…