Yogesh ..’s Post

Day 77/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Binary Search Tree to Greater Sum Tree A clean and elegant BST transformation problem. Problem idea: Convert a BST so that each node’s value becomes the sum of all values greater than or equal to it. Key idea: Reverse inorder traversal (Right → Root → Left). Why? • In a BST, inorder gives sorted order • Reverse inorder processes nodes from largest to smallest • Maintain a running sum while traversing How it works: • Start from the rightmost node (largest value) • Keep a cumulative sum variable • Add current node value to sum • Update node value with sum • Move to left subtree Time Complexity: O(n) Space Complexity: O(h) (stack / recursion depth) Big takeaway: Whenever you need greater values accumulation in BST, think of reverse inorder traversal. 🔥 This pattern is very useful in BST transformation problems. Day 77 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearchTree #Trees #Recursion #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories