Размер видео: 1280 X 720853 X 480640 X 360
Показать панель управления
Автовоспроизведение
Автоповтор
Time Complexity & Space Complexity: O(N)Code: unordered_mapm; int getMaxSum(Node *root) { // Add your code here //recursive code //optimize -> 2 lines //with node //case 1 if(!root)return 0; if(m[root])return m[root]; int withnode = root->data; //call your grandchildren if(root->left) { withnode+=getMaxSum(root->left->left); withnode+=getMaxSum(root->left->right); } if(root->right) { withnode+=getMaxSum(root->right->left); withnode+=getMaxSum(root->right->right); } //case 2 //without node //call your children int withoutnode = getMaxSum(root->left)+getMaxSum(root->right); return m[root]= max(withnode,withoutnode); }
Good and intuitive approach, other channels are mostly using the same textbook approach.
Glad it was helpful!
Very good explanation, recursion works like magic. Thanks
Thank god, she explained in English ! Also her intuition to get into the solution is pretty good.
At start I haven't even understood the problem but the way you explained the solution is wow...... Superb ❤️
Thank you so much 😀
@@probabilitycodingisfunis1 do u have insta page ??
Damn! Can’t expect for more clear explanation.
Very Nice explanation madam . Keep working hard
this is the best explanation ever possible very well explained very easy to understand thank u
Thank you so much ❤️
Excellent Explanation.
The way you explain intuition is brilliant !! Nice work
Great explanation .🙂👍
you are just amazing alisha
how the fuck can someone explain this so beautifullygreat stuff maam !!
mann gayee awesome explanation
Wonderful Explanation
Good approach ma'amVery good approach
Underrated Channel
excellent and so easy to understand
nice explanation ma'am
Thank you so much
This is so good!Thank you!
thanks for the great explanation!
very good problem solving approach
Good explain
Keep on the good work !
Thank you so much !
Damn! nice explanation
Wow
mam after how many months pf practice you solved this approach
this was good !
I did like level order traversal and did 1d dp kind but I got wrong ans for this test case [2,1,3,null,4] ans is given 7 but isn't it 6 tree : 2 1 3 4
If 4 is a child of 1 and not 3 , then 4 and 3 can be taken together and the answer will be 7
@@probabilitycodingisfunis1 Thank you for explanation. I got it I now. I misunderstood the question, thought complete level should be skipped
Awesome Explaination
unordered_mapm; int getMaxSum(Node *root) { //Recursive Solution ->Optimization using unordered_map //Base Case if(root==NULL) return 0; if(root->left==NULL && root->right==NULL) return root->data; if(m.find(root)!=m.end()) return m[root]; // Case 1 int withnode = root->data; if(root->left!=NULL){ withnode += getMaxSum(root->left->left); withnode += getMaxSum(root->left->right); } if(root->right!=NULL){ withnode += getMaxSum(root->right->left); withnode += getMaxSum(root->right->right); } //Case 2: int withoutnode = getMaxSum(root->left)+getMaxSum(root->right); m[root] = max(withnode,withoutnode); return max(withnode,withoutnode); }
Thank you Lovelesh for listing out the code
@@probabilitycodingisfunis1 The way you approach problem , its amazing
@@loveleshbhagat1114 Thank you so much! Glad you found it helpful Lovelesh 😃
Time Complexity & Space Complexity: O(N)
Code:
unordered_mapm;
int getMaxSum(Node *root)
{
// Add your code here
//recursive code
//optimize -> 2 lines
//with node
//case 1
if(!root)return 0;
if(m[root])return m[root];
int withnode = root->data;
//call your grandchildren
if(root->left)
{ withnode+=getMaxSum(root->left->left);
withnode+=getMaxSum(root->left->right);
}
if(root->right)
{
withnode+=getMaxSum(root->right->left);
withnode+=getMaxSum(root->right->right);
}
//case 2
//without node
//call your children
int withoutnode = getMaxSum(root->left)+getMaxSum(root->right);
return m[root]= max(withnode,withoutnode);
}
Good and intuitive approach, other channels are mostly using the same textbook approach.
Glad it was helpful!
Very good explanation, recursion works like magic. Thanks
Thank god, she explained in English ! Also her intuition to get into the solution is pretty good.
At start I haven't even understood the problem but the way you explained the solution is wow...... Superb ❤️
Thank you so much 😀
@@probabilitycodingisfunis1 do u have insta page ??
Damn! Can’t expect for more clear explanation.
Very Nice explanation madam . Keep working hard
this is the best explanation ever possible very well explained very easy to understand thank u
Thank you so much ❤️
Excellent Explanation.
The way you explain intuition is brilliant !! Nice work
Great explanation .🙂👍
you are just amazing alisha
how the fuck can someone explain this so beautifully
great stuff maam !!
mann gayee awesome explanation
Wonderful Explanation
Good approach ma'am
Very good approach
Underrated Channel
excellent and so easy to understand
nice explanation ma'am
Thank you so much
This is so good!
Thank you!
thanks for the great explanation!
very good problem solving approach
Thank you so much
Good explain
Keep on the good work !
Thank you so much !
Damn! nice explanation
Wow
mam after how many months pf practice you solved this approach
this was good !
Thank you so much
I did like level order traversal and did 1d dp kind but I got wrong ans for this test case [2,1,3,null,4]
ans is given 7 but isn't it 6
tree : 2
1 3
4
If 4 is a child of 1 and not 3 , then 4 and 3 can be taken together and the answer will be 7
@@probabilitycodingisfunis1 Thank you for explanation. I got it I now. I misunderstood the question, thought complete level should be skipped
Awesome Explaination
unordered_mapm;
int getMaxSum(Node *root)
{
//Recursive Solution ->Optimization using unordered_map
//Base Case
if(root==NULL) return 0;
if(root->left==NULL && root->right==NULL) return root->data;
if(m.find(root)!=m.end()) return m[root];
// Case 1
int withnode = root->data;
if(root->left!=NULL){
withnode += getMaxSum(root->left->left);
withnode += getMaxSum(root->left->right);
}
if(root->right!=NULL){
withnode += getMaxSum(root->right->left);
withnode += getMaxSum(root->right->right);
}
//Case 2:
int withoutnode = getMaxSum(root->left)+getMaxSum(root->right);
m[root] = max(withnode,withoutnode);
return max(withnode,withoutnode);
}
Thank you Lovelesh for listing out the code
@@probabilitycodingisfunis1 The way you approach problem , its amazing
@@loveleshbhagat1114 Thank you so much! Glad you found it helpful Lovelesh 😃
nice explanation ma'am
Thank you so much