Consider a high traffic website that receives millions of requests (of different types) per five minutes, the site has k (for example n = 1000) servers to proce
You are given a string of 2N characters consisting of N ‘[‘ brackets and N ‘]’ brackets. A string is considered balanced if it can be represented in the
Given a binary search tree and a key, your task to reverse path of the binary tree. Prerequisite : Reverse path of Binary tree Examples : Input : 50 / 30 70 / /
Hash Table supports following operations in Θ(1) time. 1) Search 2) Insert 3) Delete The time complexity of above operations in a self-balancing Binary Search
Given a binary search tree which is also a complete binary tree. The problem is to convert the given BST into a Min Heap with the condition that all the values
A typical Priority Queue requires following operations to be efficient. Get Top Priority Element (Get minimum or maximum) Insert an element Remove top priority
Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node. We strongly recommend to minimize the gbrowser
Given a Binary Search Tree(BST), convert it to a Binary Tree such that every key of the original BST is changed to key plus sum of all smaller keys in BST. Give
Given a BST (Binary Search Tree) that may be unbalanced, convert it into a balanced BST that has minimum possible height. Examples : Input: 30 / 20 / 10 Output:
We have a binary search tree and a number N. Our task is to find the greatest number in the binary search tree that is less than or equal to N. Print the value
Given a Binary Search Tree (BST) of integer values and a range [low, high], return count of nodes where all the nodes under that node (or subtree rooted with th
Given a Binary Search Tree (BST) and a range, count number of nodes that lie in the given range. Examples: Input: 10 / 5 50 / / 1 40 100 Range: [5, 45] Output:
Given a Binary Search Tree that contains positive integer values greater than 0. The task is to check whether the BST contains a dead end or not. Here Dead End
Given a Binary Tree, write a function that returns the size of the largest subtree which is also a Binary Search Tree (BST). If the complete Binary Tree is BST,
Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Print all the keys of tree in range k1 to k2. i.e. print all x such that
Given root of binary search tree and K as input, find K-th smallest element in BST. For example, in the following BST, if k = 3, then output should be 10, and i
I recently encountered with a question in an interview at e-commerce company. The interviewer asked the following question: There is BST given with root node wi
Given a BST and a key. The task is to find the inorder successor and predecessor of the given key. In case, if either of predecessor or successor is not present
Given Preorder traversal of a BST, check if each non-leaf node has only one child. Assume that the BST contains unique entries. Examples Input: pre[] = {20, 10,
Given a BST and a sum, find if there is a pair with given sum. Input : sum = 28 Root of below tree Output : Pair is found (16, 12) Recommended: Please try your
Given an array that stores a complete Binary Search Tree, write a function that efficiently prints the given array in ascending order. For example, given an arr
Two of the nodes of a Binary Search Tree (BST) are swapped. Fix (or correct) the BST. Input Tree: 10 / 5 8 / 2 20 In the above tree, nodes 20 and 8 must be swap
There are numerous applications we need to find floor (ceil) value of a key in a binary search tree or sorted array. For example, consider designing memory man
A quine is a program which prints a copy of its own as the only output. A quine takes no input. Quines are named after the American mathematician and logician W