Binary Search Tree to Greater Sum Tree | Brute | Better | Optimal | Leetcode 1038 | codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=8YuKhynQaqA



Duration: 27:37
6,063 views
306


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 4th Video of our Playlist "Binary Search Tree : Popular Interview Problems".
We will be solving Leetcode - 1038 -
Binary Search Tree to Greater Sum Tree | Brute Force | Better | Optimal | Leetcode 1038 | codestorywithMIK

Problem Name : Binary Search Tree to Greater Sum Tree | Brute Force | Better | Optimal | Leetcode 1038 | codestorywithMIK
Company Tags : AMAZON
My solutions on Github : https://github.com/MAZHARMIK/Intervie...
Leetcode Link :
https://leetcode.com/problems/binary-...


Approach Summary :
The approach involves converting a Binary Search Tree (BST) into a Greater Sum Tree (GST) where each node's value is updated to the sum of all values greater than or equal to it. This is achieved through a reverse in-order traversal (right-root-left) of the tree. Here's a step-by-step explanation:
Traversal Method (solve):

Base Case: If the current node is null, simply return.
Right Subtree Processing: Recursively process the right subtree to ensure all nodes with greater values are updated first.
Update Current Node: Add the current node's value to the cumulative sum and update the current node's value to this sum.
Left Subtree Processing: Recursively process the left subtree to update nodes with lesser values.
Main Function (bstToGst):

Initialize the cumulative sum to 0.
Call the solve method starting with the root node to transform the BST into a GST.
Return the modified tree's root.
This approach ensures that by the time a node is processed, all nodes with greater values have already been updated, thus maintaining the properties required for the Greater Sum Tree.


My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Subscribe to my channel :    / @codestorywithmik  
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Timelines : ⏰
00:00 - Problem Explanation

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #2024 #newyear




Other Videos By codestorywithMIK


2024-07-02Merge Nodes in Between Zeros | 2 Approaches | Leap Of Faith | Leetcode 2181 | codestorywithMIK
2024-06-30Intersection of Two Arrays II | 2 Approaches | Easy Explanations | Leetcode 350 | codestorywithMIK
2024-06-29Longest Palindromic Subsequence | Using Blue Print | DP On Strings | Leetcode 516 | DP Concepts - 25
2024-06-28Query Sum II | Segment Tree Concepts & Qns | Video 5 | codestorywithMIK
2024-06-28Longest Palindromic Substring | Recursion Memo | Bottom Up | DP On Strings | Leetcode 5
2024-06-28Range Minimum Query | Segment Tree Concepts & Qns | Video 6 | codestorywithMIK
2024-06-27All Ancestors of a Node in a Directed Acyclic Graph | 3 Approaches | Leetcode 2192 |codestorywithMIK
2024-06-26Maximum Total Importance of Roads | Thought Process | Leetcode 2285 | codestorywithMIK
2024-06-25Find Center of Star Graph | 2 Simple Approaches | Leetcode 1791 | codestorywithMIK
2024-06-24Balance a Binary Search Tree | Simple Explanation | Leetcode 1382 | codestorywithMIK
2024-06-23Binary Search Tree to Greater Sum Tree | Brute | Better | Optimal | Leetcode 1038 | codestorywithMIK
2024-06-22Segment Tree | Why size is 4*n | With Proof | Video 4
2024-06-21Count Number of Nice Subarrays | 2 Approaches | Similar Concept | Leetcode 1248 | codestorywithMIK
2024-06-21Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | Leetcode 1438 |Detailed
2024-06-19Grumpy Bookstore Owner | Simplest Thought Process | Leetcode 1052 | codestorywithMIK
2024-06-18Magnetic Force Between Two Balls | Simple Thought Process | Leetcode 1552 | codestorywithMIK
2024-06-17Segment Tree | Range Sum Query | Story To Code | Video 3
2024-06-17Minimum Number of Days to Make m Bouquets | Simple Thought Process| Leetcode 1482 | codestorywithMIK
2024-06-16Most Profit Assigning Work | Multiple Approaches | With Intuition | Leetcode 826 | codestorywithMIK
2024-06-16Segment Tree | Update Query | Story To Code | Video 2
2024-06-15Segment Tree | Introduction | Basics | Build Segment Tree | Video 1 | codestorywithMIK