I just noticed that you are one of our college alumni. I really love your content and my leetcode consistency and rating improvement is because of you. I hope we can connect some day Thanks for making iiest proud ❤️❤️
We can use short circuit evaluation so that in case first case return true, 2nd case won't be executed and hence we will able to prune some cases. return ((flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)) || (flipEquiv(root1.right, root2.left) && flipEquiv(root1.left, root2.right)));
Will Invert Binary Tree and Same Tree Question of Leetcode work here ??? If I simply call those functions??? Then can someone help me with the code in cpp calling both these functions??
Yrr tumhara channel sabka karke ek geniune dikkat ho gayi. Yaar ab jaise abhi 11 baj rhe hai, mai shaam ke side daily question solve krta hu. Ab tumne video upload kardi aur thumbnail mei likha h ki ye question recursion se hoga. Toh ab mujhe pta chal gaya ki ye recursion ka question h toh mai asaan se solve kr sakta hu. Baaki questions be it easy medium or hard sabke saath aise hi hota hai. Since I have subscribed you, latest video aa jaati aur I get to know ki iss topic ka question hai. This way meri self thinking nahi hopaati. I would suggest you upload by end of the day the answer of today's question. There is no point in uploading it very early. Jo bhi dekhega bhi video toh wo shaam mei dekhega ek baar attempt karke.
@@YashMalav-kh1ov bhai UA-cam sirf ye channel thodi dekhne ko kholta hu, aur bhi chize hai. Office mei rehta hu kabhi koi kaam padd gaya ya timepass mei hi khol liya toh UA-cam suggestions mei frequently visited channel ka recent upload dikha deta hai aur pata chal jata h kis topic se hoga daily question. Shaam ko office se aake karne baith ta hu toh uss trah ki learning nahi ho paati kyuki pta hota h kis data structure ya alog se hoga. Ab koi sawaal h uspe thumbnail mei likha h Djikstra variation, toh mujhe shaam mei pta hoga ki Djikstra lagegi. Agar topic na likha hota toh mai khud figures out krta pehle ki Djikstra lag sakti hai. Pta nahi tumlog ko ye problem kyu nahi aa rahi hai.
I just noticed that you are one of our college alumni.
I really love your content and my leetcode consistency and rating improvement is because of you.
I hope we can connect some day
Thanks for making iiest proud ❤️❤️
Which college?
@@Zoro_taoiiest shibpur
I just saw this comment.
This made my day.
Thank you so much ♥️🙏😇
Bhaiya, please make a DSA sheet with important questions for practice. It would be helpful
Please check the sheet link on my github page.
I will update them soon ♥️
github.com/MAZHARMIK
Bhaiya maine aapka graph concept wali playlist puri dekhi, aur graph samjh me bhi aane laga. Aur abhi recursion wali dekh rha hoon lekin questions nhi ban pa rhe.
We can use short circuit evaluation so that in case first case return true, 2nd case won't be executed and hence we will able to prune some cases.
return ((flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)) || (flipEquiv(root1.right, root2.left) && flipEquiv(root1.left, root2.right)));
Indeed 👌
my approach was exactly same but i was not confident on leap of faith!!
clean code, nice approach
after first 3 mins , I got the concept and solved my self
tip:avoid extra recursive calls , maintain a flag to check, whether to flip or not flip.(time , space efficient)
here's my code , thanks brother
class Solution {
private boolean compareSubTrees(TreeNode root1, TreeNode root2,boolean flip)
{
if(root1==null && root2==null)return true;
if(root1==null ||root2==null)return false;
if(root1.val!=root2.val)return false;
if(root1.left!=null && root2.left!=null && root1.left.val!=root2.left.val || root1.left!=null && root2.right!=null && root1.left.val==root2.right.val || root1.right!=null && root2.left!=null && root1.right.val==root2.left.val)flip=true;
if(flip){
return compareSubTrees(root1.left,root2.right,false) && compareSubTrees(root1.right,root2.left,false);
}
return compareSubTrees(root1.left,root2.left,false) && compareSubTrees(root1.right,root2.right,false);
}
public boolean flipEquiv(TreeNode root1, TreeNode root2) {
return compareSubTrees(root1,root2,false);
}
}
Sir can you please tell how you thought of recursion and wrote the calls?
Thanks 😊
Easy today 😊
Thank you so much bhaiyya
❤❤❤❤ bro last contest problem 4 . check if dfsstr is palindrome explain bro
badhiya
bhaiya can we use inverrt tree and same tree problem to solve this like we invert(root1) and after inverting root1 chck if root1 and root are same
Can you please upload manacher algo bhaiya...last week contest 420, there was a last question on that algo. Please🙏🏻
bool flipEquiv(TreeNode* root1, TreeNode* root2) {
if(root1 == NULL && root2 == NULL) return true;
if(root1 == NULL || root2 == NULL) return false;
if(root1->val != root2->val) return false;
// Recursively check if flipping the children results in equivalence
bool noFlip = flipEquiv(root1->left, root2->left) && flipEquiv(root1->right, root2->right);
bool flip = flipEquiv(root1->left, root2->right) && flipEquiv(root1->right, root2->left);
return noFlip || flip;
} my code
bhaiya please upload max width of ramp problem app ne kha tha hum iski monotonic stack wali approach discuss karenge
Yes i will try to upload that in weekend when I get free time ♥️
my code
class Solution {
public:
bool solve(TreeNode* head1, TreeNode* head2){
if(head1==NULL && head2==NULL) return 1;
if(head1==NULL || head2==NULL) return 0;
if(head1->val!=head2->val) return 0;
if(solve(head1->left,head2->right)==0 && solve(head1->left,head2->left)==0) return 0;
if(solve(head1->right,head2->right)==0 && solve(head1->right,head2->left)==0) return 0;
return 1;
}
bool flipEquiv(TreeNode* root1, TreeNode* root2) {
return solve(root1,root2);
}
};
Will Invert Binary Tree and Same Tree Question of Leetcode work here ???
If I simply call those functions???
Then can someone help me with the code in cpp calling both these functions??
bhaiya ye hai mera code
class Solution {
public:
void addnodes(int parent, TreeNode* node, map& mp) {
if (node == NULL)
return;
addnodes(parent, node->left, mp);
mp[parent].insert(node->val);
addnodes(parent, node->right, mp);
}
void dfs(TreeNode* node, map& mpleft, map& mpright) {
if (node == NULL) {
return;
}
dfs(node->left, mpleft, mpright);
addnodes(node->val, node->left, mpleft);
addnodes(node->val, node->right, mpright);
dfs(node->right, mpleft, mpright);
}
bool checkValid(TreeNode* node, map& left1, map& right1, map& left2, map& right2) {
if (node == NULL)
return true;
if (checkValid(node->left, left1, right1, left2, right2) == false)
return false;
if ((left1[node->val] == left2[node->val] && right1[node->val] == right2[node->val])
|| (left1[node->val] == right2[node->val] && right1[node->val] == left2[node->val])){
//skip
}
else
return false;
return checkValid(node->right, left1, right1, left2, right2);
}
bool flipEquiv(TreeNode* root1, TreeNode* root2) {
if (root1 == NULL && root2 == NULL)
return true;
if (root1 == NULL && root2 != NULL ||
root1 != NULL && root2 == NULL)
return false;
map left1;
map right1;
map left2;
map right2;
dfs(root1, left1, right1);
dfs(root2, left2, right2);
int sz1 = left1.size() + right1.size(), sz2 = left2.size() + right2.size();
if (sz1 != sz2)
return false;
return checkValid(root1, left1, right1, left2, right2);
}
};
👏👏
Yrr tumhara channel sabka karke ek geniune dikkat ho gayi. Yaar ab jaise abhi 11 baj rhe hai, mai shaam ke side daily question solve krta hu. Ab tumne video upload kardi aur thumbnail mei likha h ki ye question recursion se hoga. Toh ab mujhe pta chal gaya ki ye recursion ka question h toh mai asaan se solve kr sakta hu.
Baaki questions be it easy medium or hard sabke saath aise hi hota hai. Since I have subscribed you, latest video aa jaati aur I get to know ki iss topic ka question hai. This way meri self thinking nahi hopaati.
I would suggest you upload by end of the day the answer of today's question. There is no point in uploading it very early. Jo bhi dekhega bhi video toh wo shaam mei dekhega ek baar attempt karke.
Now unfortunately I would need to unsubscribe and search for your channel everytime for an answer.
My bad.
I will take care of this next time ♥️
@@codestorywithMIK Thanks brother. You are One of the best on YT tbh 🫱🏼🫲🏽
logo ko jeevan mai kaisi kaisi dikkate ho rhi hai😂 tumhe kon bol rha hai sedha youtube kholo phle khud se try kro potd subh 5 bje hi aa jata hai ....
@@YashMalav-kh1ov bhai UA-cam sirf ye channel thodi dekhne ko kholta hu, aur bhi chize hai. Office mei rehta hu kabhi koi kaam padd gaya ya timepass mei hi khol liya toh UA-cam suggestions mei frequently visited channel ka recent upload dikha deta hai aur pata chal jata h kis topic se hoga daily question. Shaam ko office se aake karne baith ta hu toh uss trah ki learning nahi ho paati kyuki pta hota h kis data structure ya alog se hoga.
Ab koi sawaal h uspe thumbnail mei likha h Djikstra variation, toh mujhe shaam mei pta hoga ki Djikstra lagegi. Agar topic na likha hota toh mai khud figures out krta pehle ki Djikstra lag sakti hai.
Pta nahi tumlog ko ye problem kyu nahi aa rahi hai.
bro binary tree playlist konsi hae ? Can you provide the link ?
ua-cam.com/play/PLpIkg8OmuX-K23LhcamOcDlTBisiNJy5E.html&si=ROszrnxnLF8JtCTJ
Hope this helps ♥️🙏