Leetcode 0270. Closest Binary Search Tree Value

Posted on Fri 22 November 2024 in Leetcode Premium • Tagged with bst, binary-search

Question Link : https://leetcode.com/problems/closest-binary-search-tree-value/

Difficulty: Easy

Premium: True

Question

Given the root of a binary search tree and a target value, return the value in the BST that is closest to the target. If there are multiple answers, print the smallest.   Example 1:

Input: root = [4,2 …


Continue reading

Leetcode 0173. Binary Search Tree Iterator

Posted on Sun 29 September 2024 in Leetcode • Tagged with bst

Question Link : https://leetcode.com/problems/binary-search-tree-iterator/

Difficulty: Medium

Premium: False

Question

Implement the BSTIterator class that represents an iterator over the in-order traversal of a binary search tree (BST):

BSTIterator(TreeNode root) Initializes an object of the BSTIterator class. The root of the BST is given as part of …


Continue reading

Leetcode 0098. Validate Binary Search Tree

Posted on Wed 25 September 2024 in Leetcode • Tagged with bst, recursion

Question Link : https://leetcode.com/problems/validate-binary-search-tree/

Difficulty: Medium

Premium: False

Question

Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows:

The left subtree of a node contains only nodes with keys less than the …


Continue reading

Leetcode 0501. Find Mode in Binary Search Tree

Posted on Sun 22 September 2024 in Leetcode • Tagged with bst, binary-tree-traversal-inorder, dfs

Question Link : https://leetcode.com/problems/find-mode-in-binary-search-tree/

Difficulty: Easy

Premium: False

Question

Given the root of a binary search tree (BST) with duplicates, return all the mode(s) (i.e., the most frequently occurred element) in it. If the tree has more than one mode, return them in any order …


Continue reading

Leetcode 0108. Convert Sorted Array to Binary Search Tree

Posted on Sat 14 September 2024 in Leetcode • Tagged with bst

Question Link : https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/

Difficulty: Easy

Premium: False

Question

Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.   Example 1:

Input: nums = [-10,-3,0,5,9] Output: [0,-3,9,-10,null,5] Explanation …


Continue reading

Leetcode 0938. Range Sum of BST

Posted on Tue 06 December 2022 in Leetcode • Tagged with bst, recursion

Question Link : https://leetcode.com/problems/range-sum-of-bst/

Difficulty: Easy

Premium: False

Question

Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].   Example 1:

Input: root = [10,5 …


Continue reading

Leetcode 0897. Increasing Order Search Tree

Posted on Sat 23 April 2022 in Leetcode • Tagged with bst

Question Link : https://leetcode.com/problems/increasing-order-search-tree/

Difficulty: Easy

Question

Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child …


Continue reading

Leetcode 0700. Search in a Binary Search Tree

Posted on Wed 13 April 2022 in Leetcode • Tagged with bst

Question Link : https://leetcode.com/problems/search-in-a-binary-search-tree/

Difficulty: Easy

Question

You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does …


Continue reading