Trees

Master tree traversal, manipulation, and advanced tree algorithms.

Showing 40 of 40 questions
Easy: 14
Medium: 22
Hard: 4
Question Difficulty
Check if BST is Balanced
Check if a binary search tree is height-balanced
Easy
Closest Value in BST
Find the value in BST that is closest to a given target
Easy
Lowest Common Ancestor in BST
Find the lowest common ancestor of two nodes in a binary search tree
Easy
Range Sum of BST
Calculate the sum of all node values within a given range in a BST
Easy
Search in BST
Search for a specific value in a binary search tree
Easy
BST to Greater Sum Tree
Convert BST where each node's value becomes sum of all greater values
Medium
Construct BST from Preorder
Construct a BST from its preorder traversal sequence
Medium
Convert BST to Sorted Doubly Linked List
Convert a binary search tree to a sorted doubly linked list in-place
Medium
Count Nodes in Complete BST
Count the number of nodes in a complete binary search tree efficiently
Medium
Delete Node in BST
Delete a node with given key from a binary search tree
Medium
Floor and Ceil in BST
Find floor and ceiling values for a given key in a BST
Medium
Inorder Successor in BST
Find the inorder successor of a given node in a BST
Medium
Insert into BST
Insert a new node with given value into a binary search tree
Medium
Kth Largest Element in BST
Find the kth largest value in a binary search tree
Medium
Kth Smallest Element in BST
Find the kth smallest value in a binary search tree
Medium
Find Median of BST
Find the median value in a binary search tree
Medium
Serialize and Deserialize BST
Serialize a BST to string and deserialize string back to BST
Medium
Trim a BST
Trim a BST to contain only nodes within a given range
Medium
Validate BST
Determine if a binary tree is a valid binary search tree
Medium
Recover BST
Recover a BST where exactly two nodes have been swapped
Hard
Convert Sorted Array to Binary Search Tree
Convert a sorted array to a height-balanced binary search tree.
Easy
Diameter of Binary Tree
Find the diameter (longest path) of a binary tree.
Easy
Binary Tree Inorder Traversal
Traverse a binary tree in inorder (left -> root -> right)
Easy
Invert Binary Tree
Invert (mirror) a binary tree by swapping left and right children
Easy
Maximum Depth of Binary Tree
Find the maximum depth (height) of a binary tree
Easy
Path Sum
Check if there exists a root-to-leaf path with given sum.
Easy
Postorder Traversal
Traverse binary tree in postorder (left, right, root)
Easy
Binary Tree Preorder Traversal
Traverse a binary tree in preorder (root -> left -> right)
Easy
Symmetric Tree
Check if a binary tree is symmetric around its center.
Easy
Boundary Traversal of Binary Tree
Traverse the boundary of a binary tree in anti-clockwise direction.
Medium
Construct Binary Tree from Preorder and Inorder Traversal
Construct a binary tree from preorder and inorder traversal sequences.
Medium
Count Good Nodes in Binary Tree
Count the number of nodes in a binary tree where the path from root to that node has no nodes with values greater than the current node.
Medium
Flatten Binary Tree to Linked List
Flatten a binary tree into a linked list in-place using preorder traversal.
Medium
Level Order Traversal
Traverse a binary tree level by level from left to right.
Medium
Lowest Common Ancestor
Find the lowest common ancestor of two nodes in a binary tree.
Medium
Print All Root-to-Leaf Paths
Print all root-to-leaf paths in a binary tree
Medium
Zigzag Level Order Traversal
Traverse a binary tree level by level in zigzag order
Medium
Maximum Path Sum
Find the maximum path sum in a binary tree.
Hard
Serialize and Deserialize Binary Tree
Serialize a binary tree to a string and deserialize it back to the original tree
Hard
Vertical Order Traversal of Binary Tree
Traverse a binary tree vertically and return nodes by columns
Hard