Skip to main content
109, Convert Sorted List to Binary Search Tree

I Problem

Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height-balanced binary search tree.

Example 1

Input: head = [-10, -3, 0, 5, 9]
Output: [0, -3, 9, -10, null, 5]
Explanation: One possible answer is [0, -3, 9, -10, null, 5], which represents the shown height balanced BST.


MikeAbout 2 minbinary treemediumlinked listbinary treebinary search treedivide and conquer
108, Convert Sorted Array to Binary Search Tree

I Problem

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: [0, -10, 5, null, -3, null, 9] is also accepted:


MikeAbout 3 minbinary treeeasytreebinary treebinary search treearraydivide and conquer
669, Trim a Binary Search Tree

I Problem

Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.


MikeAbout 2 minbinary treemediumbinary treebinary search treedepth first search
450, Delete Node in a BST

I Problem

Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.

Basically, the deletion can be divided into two stages:

  1. Search for a node to remove.
  2. If the node is found, delete the node.

MikeAbout 3 minbinary treemediumbinary treebinary search tree
701, Insert into a Binary Search Tree

I Problem

You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.

Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.


MikeAbout 3 minbinary treemediumbinary treebinary search tree
235, Lowest Common Ancestor of a Binary Search Tree

I Problem

Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.

According to the definition of LCA on Wikipedia: "The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself)."


MikeAbout 4 minbinary treemediumtreebinary treebinary search treedepth first search
538, Convert BST to Greater Tree

I Problem

Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.

As a reminder, a binary search tree is a tree that satisfies these constraints:


MikeAbout 3 minbinary treemediumbinary treedepth first searchbinary search tree
501, Find Mode in Binary Search Tree

I Problem

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.


MikeAbout 5 minbinary treeeasybinary treedepth first searchbinary search tree
530, Minimum Absolute Difference in BST

I Problem

Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.

Example 1

Input: root = [4, 2, 6, 1, 3]
Output: 1

Example 2

Input: root = [1, 0, 48, null, null, 12, 49]
Output: 1


MikeAbout 2 minbinary treeeasybinary treebinary search treedepth first searchbreadth first search
98, Validate Binary Search Tree

I Problem

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 node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • Both the left and right subtrees must also be binary search trees.

MikeAbout 3 minbinary treemediumbinary treedepth first searchbinary search tree
2