ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Get the Shortest distance between two nodes in BST Problem Statement: You are given the root node of BST and 2 key elements. You need to find the distance between the 2 nodes. Solution So as…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Return the sum of given range in BST. Problem Statement: You are given a root of BST and 2 values. You need to return the sum of the nodes that falls within the range. Solution For…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Kth smallest Element in a BST Problem Statement: You are given BST and a kth element in the given tree. Then you need to give the kth smallest element. Solution Solution is…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Kth Largest Element in a BST Problem Statement: You are given BST and a kth element in the given tree. Then you need to give the kth largest element. Solution Here we need…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Merge Two balanced BST Problem Statement: You are given two balanced BST, you need to merge the two given balanced BST. Solution THe solution is very simple. WKT…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Convert a normal BST into a Balanced BST Problem Statement: You are given a BST root node, you need to make it as a balanced BST. Example Input: 3 / 2 / 1 Output: 2 / \ 1 3 Solution…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Convert Binary Tree into Binary Search Tree. Example Input: 11 / \ 3 8 / \ 9 5 Output: 9 / \ 5 11 / \ 3 8 Solution The solution is simple: 1. Take the node values into an temp array by…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Construct BST from preorder traversal Problem Statement: You are given an array representing a preorder traversal of a Binary Search Tree and construct the BST. Solution WKT the…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: LCA in a BST Problem Statement: You are given a BST root node and 2 node values n1 and n2, you need to find the Lowest Common Ancestor. Solution As we know…
ProDeveloperTutorialonJanuary 19, 2025 Binary Search Trees: Convert a BST into greater sum tree Problem Statement: You are given a root node of BST. You need to convert into a greater sum tree. Example Input: 4 / \ 3 6 Output: 6 / \ 10 0…