Binary Search Tree LeetCode Problems: All 40, With Python Solutions

Every problem in this library that LeetCode tags Binary Search Tree 40 in total, 29 of them with a complete Python solution, a worked example and the time and space complexity of the approach.

  • 40 problems
  • 10 Easy
  • 27 Medium
  • 3 Hard

How Binary Search Tree problems are solved

A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Binary Search Tree problems — each one explains the approach, gives a Python template and states its complexity.

  • Tree Traversal — Choose the order — preorder, inorder, postorder, level — and the problem solves itself.

Binary Search Tree problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (10)

#ProblemDifficultyTopics
108Convert Sorted Array to Binary Search TreeEasyTree, Binary Search Tree, Array +2
501Find Mode in Binary Search TreeEasyTree, Depth-First Search, Binary Search Tree +1
530Minimum Absolute Difference in BSTEasyTree, Depth-First Search, Breadth-First Search +2
653Two Sum IV - Input is a BSTEasyTree, Depth-First Search, Breadth-First Search +4
700Search in a Binary Search TreeEasyTree, Binary Search Tree, Binary Tree
703Kth Largest Element in a StreamEasyTree, Design, Binary Search Tree +3
783Minimum Distance Between BST NodesEasyTree, Depth-First Search, Breadth-First Search +2
897Increasing Order Search TreeEasyStack, Tree, Depth-First Search +2
938Range Sum of BSTEasyTree, Depth-First Search, Binary Search Tree +1
270Closest Binary Search Tree ValuePremiumEasyTree, Depth-First Search, Binary Search Tree +2

Medium (27)

#ProblemDifficultyTopics
95Unique Binary Search Trees IIMediumTree, Binary Search Tree, Dynamic Programming +2
96Unique Binary Search TreesMediumTree, Binary Search Tree, Math +2
98Validate Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
99Recover Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
109Convert Sorted List to Binary Search TreeMediumTree, Binary Search Tree, Linked List +2
173Binary Search Tree IteratorMediumStack, Tree, Design +3
230Kth Smallest Element in a BSTMediumTree, Depth-First Search, Binary Search Tree +1
235Lowest Common Ancestor of a Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
449Serialize and Deserialize BSTMediumTree, Depth-First Search, Breadth-First Search +4
450Delete Node in a BSTMediumTree, Binary Search Tree, Binary Tree
538Convert BST to Greater TreeMediumTree, Depth-First Search, Binary Search Tree +1
669Trim a Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
701Insert into a Binary Search TreeMediumTree, Binary Search Tree, Binary Tree
1008Construct Binary Search Tree from Preorder TraversalMediumStack, Tree, Binary Search Tree +3
1038Binary Search Tree to Greater Sum TreeMediumTree, Depth-First Search, Binary Search Tree +1
1305All Elements in Two Binary Search TreesMediumTree, Depth-First Search, Binary Search Tree +2
1382Balance a Binary Search TreeMediumGreedy, Tree, Depth-First Search +3
2476Closest Nodes Queries in a Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +3
255Verify Preorder Sequence in Binary Search TreePremiumMediumStack, Tree, Binary Search Tree +4
285Inorder Successor in BSTPremiumMediumTree, Depth-First Search, Binary Search Tree +1
333Largest BST SubtreePremiumMediumTree, Depth-First Search, Binary Search Tree +2
426Convert Binary Search Tree to Sorted Doubly Linked ListPremiumMediumStack, Tree, Depth-First Search +4
510Inorder Successor in BST IIPremiumMediumTree, Binary Search Tree, Binary Tree
776Split BSTPremiumMediumTree, Binary Search Tree, Recursion +1
1214Two Sum BSTsPremiumMediumStack, Tree, Depth-First Search +4
1586Binary Search Tree Iterator IIPremiumMediumStack, Tree, Design +3
1902Depth of BST Given Insertion OrderPremiumMediumTree, Binary Search Tree, Array +2

Hard (3)

#ProblemDifficultyTopics
1373Maximum Sum BST in Binary TreeHardTree, Depth-First Search, Binary Search Tree +2
1569Number of Ways to Reorder Array to Get Same BSTHardTree, Union Find, Binary Search Tree +7
272Closest Binary Search Tree Value IIPremiumHardStack, Tree, Depth-First Search +4

When the Binary Search Tree problem arrives live

Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.