First I have completed all DSA series and now conclude this is Greatest ever DSA series to exist on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂ Thanks you.
@its_nawed4611 Жыл бұрын
If anyone wondering without adding value to map for all the nodes how can we check whether a node is visited or not here is the explanation : If you try to access a key value using indexing operator [], then 2 things can happen : 1->The map contains this key. So it will return the corresponding key value 2->The map doesn't contain the key. In this case it will automatically add a key to the map with key value null.
@invinishku15422 жыл бұрын
i was coding this question by myself and just not stored q.size() before entering into for loop ....int the for loop new elements are getting pushed and whole function was working differently.....but thanks for teaching how to debug code by printing imp things...it took me 40 mins ...but the job was done......keep working hard...cheers..
@harshpandey4190 Жыл бұрын
You should be Appreciated for explaining the toughest sum with such a ease
@verma_jay Жыл бұрын
Your explanation was this good that I coded the solution myself by just seeing the algorithm🔥
@pkyadav6230 Жыл бұрын
Really??
@Ash_9202 Жыл бұрын
@@pkyadav6230either he is better than us or he could be lying. Don't stress yourself if you weren't able to come up with a solution yourself.
@yashchauhan72212 жыл бұрын
A Single thank you comment is not enough for the efforts bhaiya don't worry about views as people are left behind becoz of your consistent nature and Big Thumbs Up 🔥🔥
I was able to write the code myself after watching the first half of the video. Thanks for the awesome content!
@anshumansharma1069 Жыл бұрын
To be honest bhtt aasan laga jaise apne sikhaya bhaiyaa💖💖
@akshithabharde053 күн бұрын
Finally I am finishing my series of Binary trees thanks a lot bhaiyaa ji i have understood this concept finally now i am moving towards BST
@janvikundnani92032 жыл бұрын
Absolutely love the way you make these hard problems seem so simple!! Thank you so much for such efforts!!🔥
@RohitKumar-oo8lo2 жыл бұрын
Agree
@RohitKumar-oo8lo2 жыл бұрын
Dhamaal machaa rha hai Course bhaiya!!!
@AA-wy9vw2 жыл бұрын
Loving the series bhaiya! Aapki consistency hume inspire karti hai aur mehnat marne ke liye
@mr.himanshu42992 жыл бұрын
thoda piche reh gya hun pr dheere dheere cover kr rha hun end takk complete krunga course ko keep uploading babbar bhai
@aqusatabassumsyedsadiqueal59202 жыл бұрын
You're continuing despite less views in later vedios , 👏👏👏
@Shyara2308 Жыл бұрын
sir aaj meko 1 and half month ho gya consist hu course kafi accha bana hai i like it . samaz nahi aa rha to me 3-4 bar piche ja kr dekh rha hu but koi boriat nahi ho rahi , love babber ke course ko love dher sara
@ramanjaneyuluv47911 ай бұрын
babbar bhayya is love 💝
@prashantshukla68702 жыл бұрын
I can say today😜 Maine toh aag lga di binary tree ko 😂😂😂😂
@lazyemperor5182 Жыл бұрын
🔥🔥🔥🔥
@keshavgambhir98942 жыл бұрын
Present bhaiya Consistency op 🔥🔥🔥🔥 Commenting for a better reach
@utkarshsingh14572 жыл бұрын
Hard level question bhi easy laga... aur pehli baar me he samajh aagya.. thanks to your explanation and to your dedication to give us such a good content!!!
@pranayavnish8028 Жыл бұрын
bro easy is liye lga because he taught the brute force soln. optimized m dfs lagana h without using any extra space. Aise hi h gfg pe HARD ka tag nhi lga hua.
@Ash_9202 Жыл бұрын
@@pranayavnish8028tbhi itna lamba solution bana hai Par kar bhi kya skte hai jb tk graphs pe na poch jaye hum
@pranayavnish8028 Жыл бұрын
@@Ash_9202 vai graphs kaha se aagya bich m?? Ye video wala soln to 1st year ke students v khud se bna lenge, This soln(as the optimal) will surely get u rejected in an interview , check leetcode discussions.
@Ash_9202 Жыл бұрын
@@pranayavnish8028 agr koi 1st year student kr skta hai to pkka intelligent hoga bhai. Mujhe to aise solution ki Intuition hi nahi aaegi. I guess I'm not that intelligent.
@JungleKiKahaniyan82 жыл бұрын
Maja aa raha hai Aapki consistency ++
@dipakkumarsingh.71513 ай бұрын
Aaj to aag lagadi bhai. dhuwa dhuwa kardiya binary tree ka
@Nishant-n8e10 ай бұрын
i did with pair function
@MohitKumar-ys8jd Жыл бұрын
Your explanation is the best!! Thanks for this amazing playlist!!
@shubhamrao5952 Жыл бұрын
This question was asked by me 2 years back in Paytm SDE 1 interview.
@KPCoder2 жыл бұрын
Thanks you sir, excellent content, no one can explain like you from basic 🙏 god bless you
@crazyduniya1282 жыл бұрын
bohot badiya question maja aa gya! wah babbar ji wah
@code_sleep_live5 ай бұрын
I think a better solution is solving using recursion after creating mapping with parent and finding target node as done in the video. What we can do is pass cur node and prev node in recursion and recursively check for left right and parent unless any of them is equal to prev node and then take the max time from the generated branches.The code will look like class Solution { int minBurnTime(Node* cur,Node* prev,map &m) { if(cur==NULL) return 0; int time=0; if(m[cur]!=prev) time=minBurnTime(m[cur],cur,m); if(cur->left!=prev) time=max(time,minBurnTime(cur->left,cur,m)); if(cur->right!=prev) time=max(time,minBurnTime(cur->right,cur,m)); return time+1; } public: int minTime(Node* root, int target) { if(root==NULL) return 0; map m; queue q; Node* tar; q.push(root); m[root]=NULL; while(!q.empty()) { Node* t=q.front(); q.pop(); if(t->data==target) tar=t; if(t->left) { m[t->left]=t; q.push(t->left); } if(t->right) { m[t->right]=t; q.push(t->right); } } return minBurnTime(tar,NULL,m)-1; } };
@ashurajput35266 ай бұрын
best explanation for burning tree on utube
@mriduljain68092 жыл бұрын
Loving the series bhaiya... Sab samajh aa rha h
@sachinrathod83192 жыл бұрын
Sahi questions tha bhai maja aa gaya solve karne ka.
@vivek254672 ай бұрын
save trees !! save nature !! save lives 🙃
@RohitKumar-lt2bo7 ай бұрын
TC: O(n) //when unordered_map is used insted of map SC: O(n)
@Phantomex984 Жыл бұрын
Here is the code with some minor updates : class Solution { private: Node* createParentMapping(Node* root, int target, map& nodeToParent) { Node* res = nullptr; queue q; q.push(root); nodeToParent[root] = nullptr; while (!q.empty()) { Node* front = q.front(); q.pop(); if (front->data == target) { res = front; } if (front->left) { nodeToParent[front->left] = front; q.push(front->left); } if (front->right) { nodeToParent[front->right] = front; q.push(front->right); } } return res; } int burnTree(Node* root, map& nodeToParent) { if (!root) { return 0; } unordered_map visited; queue q; q.push(root); visited[root] = true; int ans = 0; while (!q.empty()) { int size = q.size(); bool flag = false; for (int i = 0; i < size; i++) { Node* front = q.front(); q.pop(); if (front->left && !visited[front->left]) { flag = true; q.push(front->left); visited[front->left] = true; } if (front->right && !visited[front->right]) { flag = true; q.push(front->right); visited[front->right] = true; } if (nodeToParent[front] && !visited[nodeToParent[front]]) { flag = true; q.push(nodeToParent[front]); visited[nodeToParent[front]] = true; } } if (flag) { ans++; } } return ans; } public: int minTime(Node* root, int target) { map nodeToParent; Node* targetNode = createParentMapping(root, target, nodeToParent); int ans = burnTree(targetNode, nodeToParent); return ans; } };
@RahulKumar-wt9qc2 жыл бұрын
Jabardast bhaiya 👍👍
@amishapandey6875 Жыл бұрын
Thankyou so much Bhaiya. Can't be more thankful !
@rachit_joshi7 ай бұрын
Thank You So Much BHRATA SHREE !!!!!!!
@SauravKumar-yp1fy2 жыл бұрын
class Solution { public: void getAdjacents(Node*root,Node*parent,unordered_map&mp) { if(!root) { return; } vectortemp; if(parent!=NULL) { temp.push_back(parent->data); } if(root->left) { temp.push_back(root->left->data); } if(root->right) { temp.push_back(root->right->data); } mp[root->data]=temp; getAdjacents(root->left,root,mp); getAdjacents(root->right,root,mp); } int minTime(Node* root, int start) { // Your code goes here unordered_mapmp; getAdjacents(root,NULL,mp); unordered_mapvis; queueq; int count=0; q.push(start); while(!q.empty()) { int size=q.size(); for(int i=0;i
@madetolaugh34762 жыл бұрын
Consistency....Prathishta...Anushaashan....
@shashikantverma99312 жыл бұрын
Bhai Bhai Bhai consistency oppppoo
@suyashjain3223 Жыл бұрын
You made the Hard problem easy, Thanks a lot
@monubhargav346 Жыл бұрын
space complexity is becoming n but allowed space complexity is O(height of tree)
@parikshitgupta77112 жыл бұрын
Instead of using vis as a map, you can use a set and check ki agar set mein voh node hai ki nahi, it will save space
@ishansingh624110 ай бұрын
I am thinking mai ise adjancy list bana kr bsf chala dun usse bhi ho jayega sayad.
@suranjandhara75352 жыл бұрын
Hello Bhaiya ❤️😍😘🥰😘🥰.... Aa gya hu..... Ab to college khul chuka hai... Abhi college me hu Thanks bhaiya ❤️❤️😍😍😍😍😍😍
@tusharvaish80962 жыл бұрын
bhaiya apke is video ne toh dil jeet liya thankyou for this awesome series ;
@daipayannit-s415 Жыл бұрын
Commenting for better reach!!
@unboxtheuniverse53362 жыл бұрын
Congratulations for 125K family 🤩🥳🥳🥳 Mehnat he aapki 🤍 🚨🚨🚨🚨 Bhaiya plz make a Roadmap For InternShip 🥺 with DSA busted Course as resource 🤩
@prikshit_sharma40712 жыл бұрын
Bhaiya ham apko nam roshan krege ❤️
@shivkumar-og4ow2 жыл бұрын
Thank you bhaiya.. Consistency ++
@azaankhan52082 жыл бұрын
Superbbbbb !!! Thank you so much for all the efforts.... I have one query, how many more videos will this series going to have.. ?
@trojanhorse827810 ай бұрын
I think we should simply create a graph from the given tree and thereby the bfs will be bit more easy. That's the way I solved this question.
@SirAkPandey Жыл бұрын
Best solution for this problem 👍🏻♥️🙏
@tejashmaurya2149 Жыл бұрын
Salute You Bhaiya💯💯💯
@naveensingh_07352 жыл бұрын
Words aren't enough bade bhaiya 🙏
@prashantbirajdar92712 жыл бұрын
very nice bhaiyaa everything is understood...... bit tricky but after practicing 2 or three times it would be easy to impliment and understand ...thanks bhaiyaa... keep it up!! your dedication is inspiration to all of us...!!!
@naveensingh_07352 жыл бұрын
We will make you proud
@dwivedi60372 жыл бұрын
Bhaiya aap great ho I have no words ♥️♥️ next level 😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘😘
@Bhagwati_Jewellers.2 жыл бұрын
Amazing bhiaya 🙏
@jenithpatel55942 жыл бұрын
Here, you solved using O(N) space complexity, but in question, we require O(H) space complexity.
@letsstartwithrahul8841 Жыл бұрын
in this code no significance of bool flag because by help of flag we only save last iteration and last iteration will be save by only q.size() if no element will push in queue then this is the case when queue is empty
@Vishal-cm4dl Жыл бұрын
Yeah, simply we can increment time every time when !q.empy()
@anshikasingh4158 Жыл бұрын
boht mazza aaya pehle toh lga nhi ho paega pher yaad aaya -Just ask 1 question “ Why I started ?
@ihateracistandblackpeople4272 Жыл бұрын
I also try to take that line to motivate me but that just doesn't work for me.Can you please tell what's that keeps you motivated or I should say why you started.
@RohitSingh-hc8yi Жыл бұрын
thanks a lot bhaiya
@anuragpatel77879 ай бұрын
hnji this is anurag patel Lec 67 completed successfully ✅
@ravivishvas36762 жыл бұрын
best content ever...
@sherebanoburhani89392 жыл бұрын
Present bhaiya❤
@sumitchakrabortystudy6512 жыл бұрын
labrador traversal🤣🤣🤣🤣. btw noicely explained
@sukhpreetsingh52002 жыл бұрын
done bhaiya
@abhishekshimpi214 Жыл бұрын
Maza hi agya bhaiyya🤩🤩🔥🔥
@tanishkayadav73512 жыл бұрын
learning from the best!
@vivekrathore6030 Жыл бұрын
full code :) class Solution { public: //step-1 create mapping and return the target node Node* createParentMapping(Node* root,int target,map &nodeToParent){ Node* res = NULL; //to store the result; queue q; q.push(root); nodeToParent[root] = NULL; while(!q.empty()){ Node* front = q.front(); q.pop(); if(front->data==target){ res = front; } if(front->left){ nodeToParent[front->left] = front; q.push(front->left); } if(front->right){ nodeToParent[front->right] = front; q.push(front->right); } } return res; } int burnTree(Node* root,map &nodeToParent){ map visited; queue q; q.push(root); visited[root] = true; int ans = 0; while(!q.empty()){ bool flag = 0; int size = q.size(); for(int i=0;ileft && !visited[front->left]){ flag = 1; q.push(front->left); visited[front->left] = 1; } if(front->right && !visited[front->right]){ flag = 1; q.push(front->right); visited[front->right] = 1; } if(nodeToParent[front] && !visited[nodeToParent[front]]){ flag = 1; q.push(nodeToParent[front]); visited[nodeToParent[front]] = 1; } } if(flag==1){ ans++; } } return ans; } int minTime(Node* root, int target) { map nodeToParent; Node* targetNode = createParentMapping(root,target,nodeToParent); int ans = burnTree(targetNode,nodeToParent); return ans; } };
@afeefuddin8883 Жыл бұрын
Learnt coding, now need to learn the intiution myself P.S: Coded on my own.
@ayushp44712 жыл бұрын
Thank you bhaiya for your efforts and also your explanation is the BEST❤
@deepak44222 Жыл бұрын
happy married life to you bhaiya. 😁😁😁😁😂😂😂😂
@AbhishekGupta-tn8sp Жыл бұрын
class Solution { private: unordered_map node2Parent; unordered_map visited; queueq; Node* targetNode = NULL; int time = 0; //step 1: create node 2 parent mapping via level order traversal //and also try to find target node void getNodeToParent(Node* root, int target){ queueaux; aux.push(root); while(!aux.empty()){ Node* curr = aux.front(); aux.pop(); //checking if current node is target node if(curr->data == target){ targetNode = curr; } //set parent of root to null if(curr==root){ node2Parent[root]=NULL; } if(curr->left){ node2Parent[curr->left] = curr; aux.push(curr->left); } if(curr->right){ node2Parent[curr->right] = curr; aux.push(curr->right); } } } void burning(){ while(!q.empty()){ Node* curr = q.front(); q.pop(); if(curr==NULL){ time++; if(!q.empty()){ q.push(NULL); } } else{ visited[curr]=true; // Check for left node if(curr->left && !visited[curr->left]){ q.push(curr->left); } // Check for right node if(curr->right && !visited[curr->right]){ q.push(curr->right); } // Check for parent node Node* parent = node2Parent[curr]; if(parent && !visited[parent]){ q.push(parent); } } } } public: int minTime(Node* root, int target) { getNodeToParent(root,target); q.push(targetNode); q.push(NULL); burning(); return time-1; } };
@anuptewary30162 жыл бұрын
Present bhaiya with lot's of fire 🔥
@yashchampaneri19722 жыл бұрын
26:27 😁😁😂😂 kyu tum log ne vahi suna jo mene sunna ?