All Posts

Leetcode 938: Range Sum of BST

Given the root of a binary search tree and two integers, low and high, return the sum of values of all nodes whose values are within the inclusive range [low, high]. You can assume that all nodes in the tree have distinct values.

Leetcode 1008: Construct Binary Search Tree from Preorder Traversal

You are given an array representing the preorder traversal of a binary search tree (BST). Your task is to construct the BST from this preorder traversal and return the root of the tree.

Leetcode 1038: Binary Search Tree to Greater Sum Tree

Given the root of a Binary Search Tree (BST), convert it into a Greater Tree where each node’s value is updated to the sum of its original value and all the values greater than it in the BST. The transformation should preserve the BST structure.

Leetcode 1305: All Elements in Two Binary Search Trees

Given two binary search trees, root1 and root2, return a list containing all the integers from both trees, sorted in ascending order.

Leetcode 1382: Balance a Binary Search Tree

Given the root of a binary search tree (BST), return a balanced BST containing the same node values. A balanced BST is one where the depth of the left and right subtrees of every node never differ by more than 1.

Leetcode 2476: Closest Nodes Queries in a Binary Search Tree

You are given the root of a binary search tree (BST) and an array of queries. For each query, find the largest value smaller than or equal to the query value and the smallest value greater than or equal to the query value in the tree.