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…
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 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…
Given an array, count the total number of triplets, which leads to an inversion. If (i < j < k) and (A[i] > A[j] > A[k]), then we can say that triplet (i, j, k) Read more…
If you decide to start 2021 by creating your project, then you have many things to do right – from validating your idea of choosing a technology stack and development vendor. Building a web or Read more…