1038. Binary Search Tree to Greater Sum Tree | Recursive | Iterative | Morris Traversal
In this video, I'll talk about how to solve Leetcode 1038. Binary Search Tree to Greater Sum Tree | Recursive | Iterative | Morris Traversal - Super Important
Tree Traversal + Morris Traversal - • 94. Binary Tree Inorde...
Let's Connect:
📱Discord (Join Community) : / discord
📝Linkedin: / aryan-mittal-0077
📸 Instagram: / codewitharyanbhai
💻 Twitter - / aryan_mittal007
🤖 Github: github.com/aryan-0077
About Me:
I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
✨ Timelines✨
0:00 - Problem Explanation
2:26 - Brute Force
3:54 - Approach1 - Recursive
8:37 - Approach2 - Iterative
17:56 - Approach3 - Morris Traversal
22:56 - Point by Point Explanation
33:43 - Summing Up
✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms
Пікірлер: 15
Thanks clear explanation
thanks aryan GOAT
❤
I can't believe myself that i done this problem without watching this video . Because it's my first tree problem ,I just saw GFG how to traverse tree and came up with solution which passed all testcase in single run with time complexity O(N) class Solution { public: int sum=0; void update(TreeNode* node){ if(node==nullptr){ return; } update(node->right); sum+=node->val; node->val=sum; update(node->left); } TreeNode* bstToGst(TreeNode* root) { update(root); return root; } };
@abhinaykumarak01
3 күн бұрын
nice
@insaneclutchesyt948
2 күн бұрын
u must be a genius
@codebreaker6578
2 күн бұрын
@@insaneclutchesyt948 but didn't optimal approach
I didn't do any tree question till now should i do this ?
my dumbass thought vertical order traversal to get the sum of all the right nodes
can you please explain how recursive is using O(n) space , in itertative it's because of stack
@ajayprabhu465
3 күн бұрын
Function stack space takes O(n)
@ITACH1688
3 күн бұрын
recursive function calls are managed using call stack.
@codebreaker6578
2 күн бұрын
@@ajayprabhu465 👍
@codebreaker6578
2 күн бұрын
@@ITACH1688 👍
waiting for today's dc in place modification approach 🥲