Build a Binary Search Tree from a preorder sequence
Given a distinct sequence of keys representing the preorder sequence of a binary search tree (BST), construct a BST from it.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a distinct sequence of keys representing the preorder sequence of a binary search tree (BST), construct a BST from it.
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.
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 that is only one swap away from becoming a BST, convert it into a BST in a single traversal.
Given a binary search tree, modify it such that every key is updated to contain the sum of all greater keys present in the BST.
Given a sorted doubly linked list, in-place convert it into a height-balanced Binary Search Tree (BST). The difference between the height of the left and right subtree for every node of a height-balanced BST is never greater than 1.
Given a BST and a valid range of keys, remove nodes from BST that have keys outside the valid range.
Given a binary search tree, find a pair with a given sum present in it.
Given a BST and a positive number k, find the k’th smallest node in it.
Convert a given binary tree into a BST (Binary Search Tree) by keeping its original structure intact.
Write an efficient algorithm to replace every element of a given array with the least greater element on its right or with -1 if there are no greater elements.
A Treap data structure is basically a combination of a binary search tree and a heap.