SarvamStack

    Tree Stories

    36 stories from the epics

    Inorder Traversal

    Mahabharata — The Throne Succession — Left Branch, Then Root, Then Right Branch · Easy

    Read →

    Subtree of Another Tree

    Mahabharata — The Sub-Formation — Is One Army Arrangement Contained Within the Larger? · Easy

    Read →

    Flip Equivalent Binary Trees

    Mahabharata — The Flexible Formation — Two Trees Equal If We Allow Any Node to Flip Its Children · Medium

    Read →

    LCA of Binary Tree

    Mahabharata — The Common Ancestor — The Earliest Shared Lineage of Two Warriors · Medium

    Read →

    Search in Binary Search Tree

    Mahabharata — The BST Oracle — Finding Any Warrior in the Ordered Formation · Easy

    Read →

    LCA of BST

    Mahabharata — The BST Lineage — Using Order to Find the Common Ancestor Faster · Medium

    Read →

    LCA of Deepest Leaves

    Mahabharata — The Deepest Warriors' Common Origin — Finding the Shared Root of the Farthest Leaves · Medium

    Read →

    Two Sum IV - BST

    Mahabharata — The Paired Warriors — Do Two Values in the BST Sum to the Target? · Easy

    Read →

    Kth Smallest Element in BST

    Mahabharata — The kth Rank — Finding the kth Weakest Warrior in the Sorted Formation · Medium

    Read →

    Minimum Depth of Binary Tree

    Mahabharata — The Nearest Leaf — How Short is the Shortest Path to a Leaf? · Easy

    Read →

    Maximum Depth of Binary Tree

    Mahabharata — The Deepest Root — How Far Does the Tree Extend? · Easy

    Read →

    Preorder Traversal

    Mahabharata — The Commander First — Root, Then Left Army, Then Right Army · Easy

    Read →

    Balanced Binary Tree

    Mahabharata — The Balanced Formation — No Flank Extends More Than One Level Beyond the Other · Easy

    Read →

    Diameter of Binary Tree

    Mahabharata — The Widest Span — The Longest Path Through Any Node · Easy

    Read →

    Binary Tree Tilt

    Mahabharata — The Imbalance Score — Sum of All Nodes' Absolute Left-Right Differences · Easy

    Read →

    Check Completeness of Binary Tree

    Mahabharata — The Complete Formation — Every Level Filled Except the Last, All Left-Aligned · Medium

    Read →

    Validate BST

    Mahabharata — The Righteous Formation — Does Every Warrior Obey the BST Law? · Medium

    Read →

    Recover BST

    Mahabharata — The Misplaced Warriors — Exactly Two Nodes Were Swapped, Restore the Order · Medium

    Read →

    Path Sum

    Mahabharata — The Targeted Journey — Does Any Root-to-Leaf Path Sum to the Target? · Easy

    Read →

    Path Sum II

    Mahabharata — All the Sacred Paths — Find Every Root-to-Leaf Path that Sums to Target · Medium

    Read →

    Path Sum III

    Mahabharata — The Hidden Paths — Count All Downward Paths (Not Just Root-to-Leaf) Summing to Target · Medium

    Read →

    Sum of Root to Leaf Numbers

    Mahabharata — The Decimal Paths — Each Root-to-Leaf Path Forms a Number, Sum Them All · Medium

    Read →

    Postorder Traversal

    Mahabharata — The Final Reckoning — Left, Then Right, Then the Root Last · Easy

    Read →

    Maximum Path Sum

    Mahabharata — The Greatest Victory Path — The Maximum Sum Along Any Path in the Tree · Hard

    Read →

    Construct from Preorder and Inorder

    Mahabharata — The Reconstruction — Rebuilding the Tree from Two Traversal Records · Medium

    Read →

    Construct from Postorder and Inorder

    Mahabharata — The Bottom-Up Reconstruction — Last in Postorder is Root · Medium

    Read →

    Construct from Preorder and Postorder

    Mahabharata — The Two-Ended Reconstruction — Root Known from Both Ends, Left Root from Middle · Medium

    Read →

    Sorted Array to BST

    Mahabharata — The Perfectly Balanced Formation — Build a Height-Balanced BST from Sorted Array · Easy

    Read →

    Sorted List to BST

    Mahabharata — The Linked Chain to Balanced Formation — Convert Sorted Linked List to BST · Medium

    Read →

    Serialize and Deserialize Binary Tree

    Mahabharata — The Sacred Inscription — Encode the Entire Tree as a String, Then Restore It · Hard

    Read →

    Level Order Traversal

    Mahabharata — The Council Tiers — Visiting Every Rank of Warriors Level by Level · Medium

    Read →

    ZigZag Level Order Traversal

    Mahabharata — The Vyuha Turns — Alternating Direction at Each Level of the Formation · Medium

    Read →

    Level Order Traversal II

    Mahabharata — The Inverted Hierarchy — From Leaf Warriors to the Commander at Last · Medium

    Read →

    Invert Tree

    Mahabharata — The Mirror Army — Swap Every Warrior's Left and Right · Easy

    Read →

    Symmetric Tree

    Mahabharata — The Balanced Vyuha — Is the Formation a Perfect Mirror? · Easy

    Read →

    Same Tree

    Mahabharata — The Twin Formations — Are Two Battle Arrays Identical? · Easy

    Read →