Sir android studio waali playlist ke last app pe hu uske baad kha se practice kr skte h? Ya koi course krna chahiye, pls suggest😊
@laveshgarg21892 жыл бұрын
Thanku Bhaiya for the amazing consistency in dsa one course
@RiteshSingh-rz7tz2 жыл бұрын
Thanks for continuing this series. I am addicted to it.
@harshabhardwaj75252 жыл бұрын
why your course “JAVA| DSA + ALGO” got removed from apni kaksha?? i was following that course and was not able to complete it cz it got removed. can u please tell me where can i find it?
@aishwaryshukla8880 Жыл бұрын
Bhaiya this code is not working on gfg practice! I modified the code so that it handles when we burn from the root node itself but still a test case is failing where the tree is skewed. PLEASE DO CORRECTION 🙏🏻🛑⭕🛑⭕🛑⭕🛑⭕
@pritamsarkar33712 жыл бұрын
1st traverse the tree get all parents in a hash map , 2nd find that node, from where to start, 3rd apply bfs including left child, right child, and parent then get the maximum level from that, that will be the burning time, Thank u anuj Bhai
@pritamsarkar33712 жыл бұрын
1st and second step can be done together using a global node type variable
@abhinavvarshney63662 жыл бұрын
.... THANK YOU ANUJ BHAIYA....
@abacas21752 жыл бұрын
First comment... Bhayiya java complete course daliya please..i like ur way of teaching!!!!
@annanyavijay42672 жыл бұрын
Can we use static depth variable instead of making it a wrapper class?
@sagarchawla49262 жыл бұрын
Did you get the answer?
@subhamhazracreation56342 жыл бұрын
Bhaiya plz apni kaksha k java playlist ko unhide karne k liye kahiye...atleast for a day download kar lunga.... 39 videos dekha tha uske baad sab hide kar diya gaya hai.... plz bhaiya.... yaha aapka dsa ka series kar raha hu...aur waha java kar raha tha.....
@AjitSingh-rg3zu Жыл бұрын
Sir, the solution you gave is working only for the cases in which burning of tree starts from leaf node. Could you please recheck it and confirm if the solution will run for all cases or not
@akshaypatil89405 ай бұрын
I have modified it to make it right.
@akshaypatil89405 ай бұрын
If (target == root.data) { Int height = Math.max (burnTree(root.right), burnTree(root.left)); ans = Math.max(ans, height); return 1; }
@rajeevshetty89294 ай бұрын
@@akshaypatil8940 return ans
@ashwiniskumar42752 жыл бұрын
Will this work only for burn from leaf node or burn from any target node.
@yashyadav79272 жыл бұрын
same question ... bhaiya if u there plz reply us
@vasuaggarwal-p2k7 ай бұрын
Can we use greedy by taking the node which in the centre of the most depth path
@mdnayab58392 жыл бұрын
Please suggest if we want to burn from root node???????🤔
@yashwantdwala29182 жыл бұрын
height of tree
@aishwaryshukla8880 Жыл бұрын
@@yashwantdwala2918 bro skewed tree wala test case fir bhi fail ho rha hai gfg me
@rhinoara71192 жыл бұрын
Bhiya ek doubt, code meh ek 100 size ka array difine Kare tho vo constant space complexity mane jayega?
@tusharsharma67122 жыл бұрын
no
@sagarchawla49262 жыл бұрын
Yes
@laveshgarg21892 жыл бұрын
Bhaiya the approach was mind blowing maza aa gaya Thanku Bhaiya
@reenayadav84682 жыл бұрын
Thank you sir
@nittinrana22772 жыл бұрын
Bahiya thanks for maintaining consistency
@keshavkamalkarn14312 жыл бұрын
Thankyou bhai for your guidance and Bhaiya Is data structure and algorithm different for different languages?
@warriorgaming95092 жыл бұрын
NO
@Sanyamjain772 жыл бұрын
Thanks for this solution, Actually in yesterday's weekly contest this problem - "Amount of time for binary tree to get infected" came and I was not able to solve it. All the other channels were providing the (tree -> graph then bfs) solution. But, I wanted to solve the problem using recursion and simple tree traversal. Your video really helped me. Thanks a lot for your efforts.
@rohandikshit2171 Жыл бұрын
Can you share that code, I am having some issues in getting all the test cases passed.
@Sanyamjain77 Жыл бұрын
@@rohandikshit2171 Yeah sure, here it is: class Solution { static int ans; class Depth { int d; Depth(int d){ this.d = d; } } int height(TreeNode node){ if(node == null) return 0; int lh = height(node.left); int rh = height(node.right); return Math.max(lh, rh) + 1; } int helper(TreeNode node, int target, Depth depth){ if(node == null) return 0; if(node.val == target){ depth.d = 0; int lh = height(node.left); int rh = height(node.right); ans = Math.max(lh, rh); return 0; } Depth ld = new Depth(-1); Depth rd = new Depth(-1); int lh = helper(node.left, target, ld); int rh = helper(node.right, target, rd); if(ld.d > -1){ ans = Math.max(ld.d + 1 + rh, ans); depth.d = ld.d + 1; }else if(rd.d > -1){ ans = Math.max(rd.d + 1 + lh, ans); depth.d = rd.d + 1; } return Math.max(lh, rh) + 1; } public int amountOfTime(TreeNode root, int start) { helper(root, start, new Depth(-1)); return ans; } }
@rohandikshit2171 Жыл бұрын
@@Sanyamjain77 Thanks👍
@Sanyamjain77 Жыл бұрын
@@rohandikshit2171 You're welcome!
@jagankumarpatra Жыл бұрын
@@Sanyamjain77 galat he code gfg me chal nehi raha he
@saritaprasad4295 Жыл бұрын
Thanks
@Lifeofkashh312 жыл бұрын
agya samjh rhanks a lot
@aryanvarma25362 жыл бұрын
Hello bhaiya
@Lifeofkashh312 жыл бұрын
bhiya ye samajh ni aya kya karu@anuj bhiya can u explain why we are having static class sepaerately for that depth
@sadavarshsaini98012 жыл бұрын
Bro m jab bhi kisi website se koi question karta hu tab mujhe question hi samjh nhi aata ki kya pucha h jab ki code mujhe aata rhta h but question nhi samjh pata kya pucha h isliye kbhi Kar nhi pata please guide me
@sdwivedi2 жыл бұрын
Thanks bhaiya
@pkyadav6230 Жыл бұрын
7:24 that's ampersand ' &'
@sudhanshudubey72672 жыл бұрын
bhaiya please make video on hackathons
@chinmaychaudhari41432 жыл бұрын
Bhaiya topic wise dsa ki ek question sheet banva do na ... That would help us lot to practice while learning dsa...
@sarangavadiya70872 жыл бұрын
thank you bhaiya.
@laplinanayak76882 жыл бұрын
how we can install jdk in chrombook please upload vedio on this topic
@subhankarpal28002 жыл бұрын
Sir I did this code on GFG Practice ,I understand whole logic after that I tried by my own but many times I got different result but now I wrote code as same as in your video but now still got different and , did not run any test case please help me sir , This is the Code Output --------------------------------------- 1 2 3 4 5 N 6 N N 7 8 N 9 10 11 N N N 12 N N N 13 8 Your Output: 8 Expected Output: 7 Main code ----------------------- static class Depth{ int d; public Depth(int d){ this.d = d; } } public static int minTime(Node root, int target) { // Your code goes here Depth depth = new Depth(-1); burn(root,target,depth); return ans; } static int ans = -1; public static int burn(Node root,int target,Depth depth){ if(root == null)return 0; if(root.data == target){ depth.d = 1; return 1; } Depth ld = new Depth(-1); Depth rd = new Depth(-1); int lh = burn(root.left,target,ld); int rh = burn(root.right,target,rd); if(ld.d != -1){ ans = Math.max(ans,ld.d+1+rh); depth.d = ld.d+1; } else if(rd.d != -1){ ans = Math.max(ans,rd.d+1+lh); depth.d = rd.d+1; } return Math.max(lh,rh)+1; }
@geetikabhatnagar8113 Жыл бұрын
int burn(Node* root,int target,int &d){ if(root==NULL) return 0; int ld=-1; int rd=-1; int lh=burn(root->left,target,ld); int rh=burn(root->right,target,rd); if(ld!=-1){ ans=max(ans,ld+1+rh); d=ld+1; } else if(rd!=-1){ ans=max(ans,rd+1+lh); d=rd+1;} if(root->data==target){ d=0; //start depth from 0 ans=max(ans,max(lh,rh)); //add this for burn from any node return 0; }
@bharatDarshaByDrone2 жыл бұрын
Felling First With 6 others
@pranavmittal82492 жыл бұрын
Bhaiya ek video git commands ke uper bhi bna 😣
@ankushaviraj82922 жыл бұрын
Bhaiya Java ka full course apni kasha pe show nahi hora hai kaha se dekhe
@payaskakar39382 жыл бұрын
Wonder how people come up with the approach in the interview, if they hadn't solved it before.😶
@k9killer2 жыл бұрын
no one bro , and interview me standard questions hi puche jate hai , so worry not
@priyanshumohanty52612 жыл бұрын
1:16 Poora ka poora tree swaha 😂
@26.ritukumari642 жыл бұрын
Swahaaa
@mrrishiraj882 жыл бұрын
🙏👍👍
@lokeshhans50362 жыл бұрын
Bhai me ak middle family se belong karta hu or mene ak laptop kharida 50000 ka 2 mahine Pehle or use ghar se koi chori karke le gya or college fess bhi nhi de abhi app meri help kr do plz 🙏🙏🙏🙏🙏
@arpanmaheshwari22902 жыл бұрын
First
@good114 Жыл бұрын
💕❤️
@i_nishantjain11 ай бұрын
for those who are finding why this code isn't working, let me tell you if root itself is the target then it returns 1 hence it fails just edit the code a little bit move if condition at line 36 to line 53 and replace return 1 with ans = Math.max(lh, rh); code- public static int burn(Node root,int target,Depth depth){ if(root == null)return 0; Depth ld = new Depth(-1); Depth rd = new Depth(-1); int lh = burn(root.left,target,ld); int rh = burn(root.right,target,rd); if(ld.d != -1){ ans = Math.max(ans,ld.d+1+rh); depth.d = ld.d+1; } else if(rd.d != -1){ ans = Math.max(ans,rd.d+1+lh); depth.d = rd.d+1; } if(root.data == target){ depth.d = 0; ans = Math.max(lh, rh); } return Math.max(lh,rh)+1; }
@shyamal_maity2 жыл бұрын
Bhaiya apne wo video kyun delete kiya "Reply to apni kaksa" ? Apka koi dosh nhi hai. Darna to usko chahiye. We are with you. Love you ❤️ kzbin.info/www/bejne/iXybdYKJdrWCebs
@dev_with_haresh Жыл бұрын
Too hard 😢
@subhankarpal28002 жыл бұрын
Sir I did this code on GFG Practice ,I understand whole logic after that I tried by my own but many times I got different result but now I wrote code as same as in your video but now still got different and , did not run any test case please help me sir , This is the Code Output --------------------------------------- 1 2 3 4 5 N 6 N N 7 8 N 9 10 11 N N N 12 N N N 13 8 Your Output: 8 Expected Output: 7 Main code ----------------------- static class Depth{ int d; public Depth(int d){ this.d = d; } } public static int minTime(Node root, int target) { // Your code goes here Depth depth = new Depth(-1); burn(root,target,depth); return ans; } static int ans = -1; public static int burn(Node root,int target,Depth depth){ if(root == null)return 0; if(root.data == target){ depth.d = 1; return 1; } Depth ld = new Depth(-1); Depth rd = new Depth(-1); int lh = burn(root.left,target,ld); int rh = burn(root.right,target,rd); if(ld.d != -1){ ans = Math.max(ans,ld.d+1+rh); depth.d = ld.d+1; } else if(rd.d != -1){ ans = Math.max(ans,rd.d+1+lh); depth.d = rd.d+1; } return Math.max(lh,rh)+1; }
@anuj21942 жыл бұрын
same bro
@GxG_Glory2 жыл бұрын
Same :"(
@mrsmurf9112 жыл бұрын
@@GxG_Glory This approach will work only if we start to burn form the leaf node
@hamzaansari57142 жыл бұрын
Thank you bhai
@subhankarpal28002 жыл бұрын
Sir I did this code on GFG Practice ,I understand whole logic after that I tried by my own but many times I got different result but now I wrote code as same as in your video but now still got different and , did not run any test case please help me sir , This is the Code Output --------------------------------------- 1 2 3 4 5 N 6 N N 7 8 N 9 10 11 N N N 12 N N N 13 8 Your Output: 8 Expected Output: 7 Main code ----------------------- static class Depth{ int d; public Depth(int d){ this.d = d; } } public static int minTime(Node root, int target) { // Your code goes here Depth depth = new Depth(-1); burn(root,target,depth); return ans; } static int ans = -1; public static int burn(Node root,int target,Depth depth){ if(root == null)return 0; if(root.data == target){ depth.d = 1; return 1; } Depth ld = new Depth(-1); Depth rd = new Depth(-1); int lh = burn(root.left,target,ld); int rh = burn(root.right,target,rd); if(ld.d != -1){ ans = Math.max(ans,ld.d+1+rh); depth.d = ld.d+1; } else if(rd.d != -1){ ans = Math.max(ans,rd.d+1+lh); depth.d = rd.d+1; } return Math.max(lh,rh)+1; }
@prateekgaur27092 жыл бұрын
if(root.data == target){ depth.d = 1; //change it to 0; return 1; } 2 test case will run. But 3rd one wont.Because this code is fine only for when leaf node is burnt first.