Tree Stories
36 stories from the epics
Inorder Traversal
Mahabharata — The Throne Succession — Left Branch, Then Root, Then Right Branch · Easy
Subtree of Another Tree
Mahabharata — The Sub-Formation — Is One Army Arrangement Contained Within the Larger? · Easy
Flip Equivalent Binary Trees
Mahabharata — The Flexible Formation — Two Trees Equal If We Allow Any Node to Flip Its Children · Medium
LCA of Binary Tree
Mahabharata — The Common Ancestor — The Earliest Shared Lineage of Two Warriors · Medium
Search in Binary Search Tree
Mahabharata — The BST Oracle — Finding Any Warrior in the Ordered Formation · Easy
LCA of BST
Mahabharata — The BST Lineage — Using Order to Find the Common Ancestor Faster · Medium
LCA of Deepest Leaves
Mahabharata — The Deepest Warriors' Common Origin — Finding the Shared Root of the Farthest Leaves · Medium
Two Sum IV - BST
Mahabharata — The Paired Warriors — Do Two Values in the BST Sum to the Target? · Easy
Kth Smallest Element in BST
Mahabharata — The kth Rank — Finding the kth Weakest Warrior in the Sorted Formation · Medium
Minimum Depth of Binary Tree
Mahabharata — The Nearest Leaf — How Short is the Shortest Path to a Leaf? · Easy
Maximum Depth of Binary Tree
Mahabharata — The Deepest Root — How Far Does the Tree Extend? · Easy
Preorder Traversal
Mahabharata — The Commander First — Root, Then Left Army, Then Right Army · Easy
Balanced Binary Tree
Mahabharata — The Balanced Formation — No Flank Extends More Than One Level Beyond the Other · Easy
Diameter of Binary Tree
Mahabharata — The Widest Span — The Longest Path Through Any Node · Easy
Binary Tree Tilt
Mahabharata — The Imbalance Score — Sum of All Nodes' Absolute Left-Right Differences · Easy
Check Completeness of Binary Tree
Mahabharata — The Complete Formation — Every Level Filled Except the Last, All Left-Aligned · Medium
Validate BST
Mahabharata — The Righteous Formation — Does Every Warrior Obey the BST Law? · Medium
Recover BST
Mahabharata — The Misplaced Warriors — Exactly Two Nodes Were Swapped, Restore the Order · Medium
Path Sum
Mahabharata — The Targeted Journey — Does Any Root-to-Leaf Path Sum to the Target? · Easy
Path Sum II
Mahabharata — All the Sacred Paths — Find Every Root-to-Leaf Path that Sums to Target · Medium
Path Sum III
Mahabharata — The Hidden Paths — Count All Downward Paths (Not Just Root-to-Leaf) Summing to Target · Medium
Sum of Root to Leaf Numbers
Mahabharata — The Decimal Paths — Each Root-to-Leaf Path Forms a Number, Sum Them All · Medium
Postorder Traversal
Mahabharata — The Final Reckoning — Left, Then Right, Then the Root Last · Easy
Maximum Path Sum
Mahabharata — The Greatest Victory Path — The Maximum Sum Along Any Path in the Tree · Hard
Construct from Preorder and Inorder
Mahabharata — The Reconstruction — Rebuilding the Tree from Two Traversal Records · Medium
Construct from Postorder and Inorder
Mahabharata — The Bottom-Up Reconstruction — Last in Postorder is Root · Medium
Construct from Preorder and Postorder
Mahabharata — The Two-Ended Reconstruction — Root Known from Both Ends, Left Root from Middle · Medium
Sorted Array to BST
Mahabharata — The Perfectly Balanced Formation — Build a Height-Balanced BST from Sorted Array · Easy
Sorted List to BST
Mahabharata — The Linked Chain to Balanced Formation — Convert Sorted Linked List to BST · Medium
Serialize and Deserialize Binary Tree
Mahabharata — The Sacred Inscription — Encode the Entire Tree as a String, Then Restore It · Hard
Level Order Traversal
Mahabharata — The Council Tiers — Visiting Every Rank of Warriors Level by Level · Medium
ZigZag Level Order Traversal
Mahabharata — The Vyuha Turns — Alternating Direction at Each Level of the Formation · Medium
Level Order Traversal II
Mahabharata — The Inverted Hierarchy — From Leaf Warriors to the Commander at Last · Medium
Invert Tree
Mahabharata — The Mirror Army — Swap Every Warrior's Left and Right · Easy
Symmetric Tree
Mahabharata — The Balanced Vyuha — Is the Formation a Perfect Mirror? · Easy
Same Tree
Mahabharata — The Twin Formations — Are Two Battle Arrays Identical? · Easy