Delete Node in a BST
Find and delete a node from a BST while maintaining BST properties using in-order successor.
webcoderspeed.com
54 articles
Find and delete a node from a BST while maintaining BST properties using in-order successor.
Flatten a binary tree to a linked list in-place using pre-order traversal order.
Connect each node to its next right node using BFS level order or O(1) space pointer manipulation.
Find all nodes at distance K from a target node by building parent pointers then doing BFS.
Compute the total sum of all root-to-leaf numbers formed by concatenating digits along each path.
Find the maximum width of a binary tree where width is measured from leftmost to rightmost non-null node per level.
Count nodes where no node on the root-to-node path has a value greater than the node itself.
Replace each node value with the sum of all values greater than or equal to it using reverse in-order traversal.
Find all duplicate subtrees by serializing each subtree and using a hash map to detect duplicates.
Generate all structurally unique BSTs with values 1 to n using divide and conquer with memoization.
Trim a BST so all values lie within [low, high] by recursively pruning out-of-range subtrees.
Serialize a BST to a compact preorder string and reconstruct it using the min-max BST property.
Group tree nodes by vertical column then row, sorting by value within same position using BFS with coordinates.
Find path directions between two tree nodes by finding LCA then building paths from LCA to each target.
Verify a binary tree is complete using BFS: once a null child is seen, no more non-null nodes should follow.
Find and swap the two misplaced nodes in a BST using in-order traversal to detect the violations.
Maximize robbery from a tree-structured neighborhood where adjacent (parent-child) nodes cannot both be robbed.
Find minimum cameras to monitor all nodes using greedy bottom-up: prefer placing cameras at parents of uncovered leaves.
Count minimum moves to distribute coins evenly by tracking excess/deficit coins flowing through each edge.
Find the Kth ancestor of any tree node in O(log k) per query using binary lifting (sparse table DP).
Find the maximum path sum in a binary tree where the path can start and end at any node.
Serialize a binary tree to string and back using BFS level-order or DFS preorder with null markers.
Find the maximum sum of any BST subtree within a binary tree using post-order DFS returning subtree metadata.
Reconstruct a BST from its preorder traversal in O(n) using min-max bounds to place each node.
Collect leaves by height (distance from leaf) repeatedly, returning all leaves at each height level.
Count nodes in a complete binary tree in O(log^2 n) by comparing left and right heights to identify full subtrees.
Find minimum seconds to collect all apples in a tree by DFS: include a subtree path only if it contains apples.
Find the maximum |a - b| for any ancestor-descendant pair by tracking min and max values along each root-to-leaf path.
Find the longest zigzag path in a binary tree where you alternate left-right directions at each step.
Compute sum of distances from every node to all others in O(n) using two DFS passes with rerooting technique.
Count the number of structurally unique BSTs with n nodes using Catalan numbers and DP.
Perform level-order traversal of an N-ary tree using BFS, collecting all children at each level.
Remove all subtrees that do not contain a 1 by recursively returning null for subtrees with only zeros.
Find the level with the maximum sum using BFS level-order traversal to compute each level's total.
Find lexicographically smallest string from any leaf to root by collecting and comparing reversed paths.
Find time for infection to spread through entire tree from a start node by converting to graph then doing BFS.
Find minimum swaps to sort each level of a binary tree using BFS and cycle-detection in permutation sorting.
Implement an in-order BST iterator with O(h) space using a stack to simulate recursive in-order traversal.
Sum all root-to-leaf path sums in a tree encoded as 3-digit integers using a hashmap to decode tree structure.
Find k values closest to target in a BST using two in-order iterators (forward and reverse) with a two-pointer merge.
Transform a binary tree so every right child becomes a sibling and left child becomes parent using iterative rotation.
Find the inorder successor of a node in a BST when you have access to parent pointers.
Find second minimum value in a special binary tree where root is min and each node equals min of its children.
Build a preorder string representation of a binary tree using parentheses to show tree structure.
Insert a new row of nodes at a given depth in a binary tree using BFS to reach the target depth level.
Sum all nodes at the deepest level of a binary tree using BFS to process level by level.
Determine if two nodes are cousins (same depth, different parents) using BFS to track depth and parent.
Count nodes in complete binary tree in O(log^2 n) by comparing left vs right subtree heights recursively.
Insert a value into a BST by traversing left/right based on comparisons until reaching a null position.
Traverse an N-ary tree in preorder and postorder using DFS with a stack or recursion.
Build a quad tree from a 2D grid by recursively checking if a region is uniform and splitting into four quadrants.
Rearrange a BST into a right-skewed tree with no left children using in-order traversal.
Count nodes where node value equals the average of all values in its subtree using post-order DFS returning sum and count.
Complete Trees section recap covering 9 core patterns, complexity guide, and interview problem index.