Binary Tree Problems: Mirror Tree | Two Nodes are Cousins | Check for Balanced Tree | Spiral Form

  Рет қаралды 26,685

Coder Army

Coder Army

Күн бұрын

Пікірлер: 134
@CoderArmy9
@CoderArmy9 9 ай бұрын
Like Target 1k✅
@DelightfulTreeSwing-qo6tm
@DelightfulTreeSwing-qo6tm 9 ай бұрын
Bhaiya March main 100k
@joychakraborty4367
@joychakraborty4367 9 ай бұрын
Done bhaiya
@vikaspandit-f3h
@vikaspandit-f3h 8 ай бұрын
ho jaayega sir aag jaruur lagega
@Gurmeet-z8u
@Gurmeet-z8u 2 ай бұрын
Day 152/180 ki video kha h?
@vinaymaurya4895
@vinaymaurya4895 9 ай бұрын
Yar views 3k aur likes sirf 200 itna quality content mil rha h free me, ab kya chahiye bhai log? Har kisi ne laptop me pdha diya h sare courses me lekin sirf rohit bhaiya ne hi itna quality content ko board pe cover kr rhe hn, kitna efforts lgate hn, koi faltu bkwas nhi koi promotion nhi na hi koi faltu ka excuse ki maine job aap logon ko pdhane k liye quit kr di, itna high quality content de rhe hn thoda support krne me kya dikkat h,plz bhai support kro yr plz humble request sbse 🙏🙏🙏
@RahulGupta-wv7lv
@RahulGupta-wv7lv 3 ай бұрын
Bhai ye fake id rohit bhai ke he hai kya
@rasheedahmad5611
@rasheedahmad5611 7 ай бұрын
your teaching style is just amazing. soon you will touch 1M subscriber.
@DelightfulTreeSwing-qo6tm
@DelightfulTreeSwing-qo6tm 9 ай бұрын
Bhaiya maine 4 problems khud se solve kiya tha except for spiral transversal ….. bhaiya apke videos se mujhe bhut kuch sikhne ko mila hai … dry run and thinking process … thanks for teaching us .
@nidhiraj9686
@nidhiraj9686 9 ай бұрын
Bhaiya 2 question khud se hue. Boht acha lecture tha ye. Boht kuch sikhne ko mila ❤❤
@Aniruddha_Mukherjee
@Aniruddha_Mukherjee 9 ай бұрын
Bhaiya 1 problem khudse solve kar liya tha , aur 2nd problem ka algo khud se soch liya tha lekin code nhi ho paya. Aaj ke lecture se bohot kuch seekha , aur logic building bhi improve ho raha hain. 😊
@neelmishra5304
@neelmishra5304 9 ай бұрын
51:34 ans- if(valid) conditional statement was written before so that whenever the valid becomes zero we dont need to traverse the whole tree and it return from the node where valid becomes zero.
@akashkewat1219
@akashkewat1219 9 ай бұрын
Aaj Leetcode POTD mei bhi same question tha bhaiya. Code kafi accche hai tree ke.
@chanchalsoni7535
@chanchalsoni7535 5 ай бұрын
highly underrated channel😐 why dont people like the videos....i feel so bad .....
@fachoyt9686
@fachoyt9686 5 ай бұрын
I feel so much more confident in Binary Tree after watching your videos. Thanks for being such a great resource!
@zafrul_islam
@zafrul_islam 9 ай бұрын
bhaiya khud se ek bhi problem solve nhi hui but maja aaya sikh kr 😊😊
@rrr9848
@rrr9848 8 ай бұрын
Congratulations bhaiya 🎉
@asad_iliyas
@asad_iliyas 7 ай бұрын
51:00 : if(valid==0) => It means unbalanced node is found and we will directly come out of function by returning -1 , and our valid would have become 0 and we will return it in our main function.
@kamleshregar5880
@kamleshregar5880 4 ай бұрын
very good lectures. keep doing it for us. thank you bro for your hardwork
@heetpatel3037
@heetpatel3037 6 ай бұрын
Aapka jitna shukriya da karu utna kam hai
@alltech_info
@alltech_info 2 ай бұрын
Shuru majboori me kiye the ab maja aa rha hai😇😂
@devendrasharma8750
@devendrasharma8750 Ай бұрын
bhaiya did level order traversal in spiral by my self. thanku bhaiya❤‍🩹
@Noobiee_FPS
@Noobiee_FPS 9 ай бұрын
sab kuch kr liya bhaiya sare questions kr liya spiral wale code mai confuse ho gya tha par dry run kra toh sab smjh mai aa gya tha first three question approach ka idea lga liya tha bss code nhi kra tha dono question video dekh ke ek cheez smjha aaya tree ko traverse krna aana chaiye tabhi question hoge
@heetpatel3037
@heetpatel3037 6 ай бұрын
Jai shree Ram ❤️ Bohot bohot dhanyawad aapka bhaiya
@Sanataniblood-mb5pu
@Sanataniblood-mb5pu 5 ай бұрын
Content outstanding and bhaiya is also outstanding 😂🙏🏻
@RohitKumar-gj2px
@RohitKumar-gj2px 4 ай бұрын
Thanku so much for best quality content . Your style of teaching is amazing and i am enjoying your videoes . LOVE YOU BROTHER ❤❤
@ankushladani496
@ankushladani496 9 ай бұрын
Bhaiya Khali second wali if statement nahi kar paya Baki pura solution khudse implement kar liya tha...😊❤
@anupammishra6514
@anupammishra6514 9 ай бұрын
1:44:54 maja aa gya bhaiya ❤❤......1 questions solve hua hamse 🥲🥲
@um6819
@um6819 8 ай бұрын
UPDATED CODE if test case not passed in GFG for TC no. 1075 (see the previous line before the last line) everything will be same bool isParent(Node *root, int a, int b){ if(root==NULL) return 0; if(root->left && root->right){ if(root->left->data == a && root->right->data == b) return 1; if(root->left->data == b && root->right->data == a) return 1; } return (isParent(root->left, a, b) || isParent(root->right, a, b)); } bool isCousins(Node *root, int a, int b) { queue q; q.push(root); int level = 0; int l1 = -1, l2 = -1; while(!q.empty()){ int n = q.size(); while(n--){ Node* temp = q.front(); q.pop(); if(temp->data==a) l1 = level; if(temp->data==b) l2 = level; if(temp->left) q.push(temp->left); if(temp->right) q.push(temp->right); } level++; if(l1!=l2) return 0; if(l1!=-1) break; } if(l1==-1 && l2==-1) return 0; //updated line, if a and b is not present anywhere in the tree return !isParent(root, a, b);
@CoderArmy9
@CoderArmy9 8 ай бұрын
Good Job bhai, they have updated the TC.
@haardikmadaan1644
@haardikmadaan1644 8 ай бұрын
thanks bro....i was so confused in this
@nownow1025
@nownow1025 27 күн бұрын
it still fails t.c 219
@JatinKansal-z5b
@JatinKansal-z5b 7 күн бұрын
Still not working plz help
@nownow1025
@nownow1025 28 күн бұрын
Great explanation bhaiya. Thank you so much ♥
@ankushladani496
@ankushladani496 9 ай бұрын
Sab kuch chamak gaya Bhaiya...❤🎉
@rishavdobriyal8201
@rishavdobriyal8201 18 күн бұрын
amazing explaination sir
@akashkumawat-xk1eg
@akashkumawat-xk1eg 2 ай бұрын
Maza aa gaya❤❤ I solved all problems by myself😀😀
@Vardanaggarwal
@Vardanaggarwal 8 ай бұрын
thanks bhaiya amazing series leking ek bhi problem khud se nhi huyi.
@GOATSOFFOOTBALL
@GOATSOFFOOTBALL 4 ай бұрын
Thodasa brainstorming tha session but loved it,best explanation
@amanprajapati6301
@amanprajapati6301 8 ай бұрын
thank u bhaiya for providing quality content dil se
@sunnyrai4329
@sunnyrai4329 9 ай бұрын
Congratulations❤ almost 3 que solved by self
@AnordinaryMan007
@AnordinaryMan007 9 ай бұрын
Best course ❤
@Md.FarhanMasud-u8x
@Md.FarhanMasud-u8x 2 ай бұрын
// Spiral Print Binary tree using deque vector findSpiral(Node *root) { int n; vector ans; deque q; q.push_back(root); while (q.size()) { // print Right to left & Reverse left to right n = q.size(); while (n--) { Node *temp = q.back(); q.pop_back(); ans.push_back(temp->data); if (temp->right) q.push_front(temp->right); if (temp->left) q.push_front(temp->left); } // Print left to right and Reverse right to left n = q.size(); while (n--) { Node *temp = q.front(); q.pop_front(); ans.push_back(temp->data); if (temp->left) q.push_back(temp->left); if (temp->right) q.push_back(temp->right); } } return ans; }
@rishusachan2618
@rishusachan2618 4 ай бұрын
Thanku Bhaiya, ekdum accha say chmak gya 😍😇
@ayushpanwar1671
@ayushpanwar1671 3 ай бұрын
bhaiya sab samaj agya... one day you will be recognized
@rocketgamerzz.7577
@rocketgamerzz.7577 5 ай бұрын
Problem 4 can be done using a single deque instead of two stacks for odd level push at back and take from front and for even level vice versa here's the code for your reference deque q; q.push_back(root); vector ans; while(!q.empty()) { int n = q.size(); while(n--) { //odd level k liye Node *temp = q.back(); q.pop_back(); ans.push_back(temp->data); if(temp->right) { q.push_front(temp->right); } if(temp->left) { q.push_front(temp->left); } } n = q.size(); // even level k liye while(n--) { Node *temp=q.front(); ans.push_back(temp->data); q.pop_front(); if(temp->left) { q.push_back(temp->left); } if(temp->right) { q.push_back(temp->right); } } }
@kumarashutosh-p3n
@kumarashutosh-p3n 9 ай бұрын
class Solution { public: //Function to check if two trees are identical. bool isIdentical(Node *r1, Node *r2) { vectora; vectorb; queuep; queueq; Node* temp; Node* dummy; p.push(r1); q.push(r2); while(!p.empty()){ temp=p.front(); p.pop(); a.push_back(temp->data); if(temp->left) p.push(temp->left); if(!temp->left) a.push_back(0); if(!temp->right) a.push_back(0); if(temp->right) p.push(temp->right); } while(!q.empty()){ dummy=q.front(); q.pop(); b.push_back(dummy->data); if(dummy->left) q.push(dummy->left); if(!dummy->left) b.push_back(0); if(!dummy->right) b.push_back(0); if(dummy->right) q.push(dummy->right); } if(a==b) return true; else return false; } };
@KUNALGAUTAM-bf1yy
@KUNALGAUTAM-bf1yy Ай бұрын
iss tarike se likhna hoga code aage khain bhi? like exam intreview
@amybross
@amybross 4 ай бұрын
thank you brother for your great effort
@5harshitshrivastava
@5harshitshrivastava 4 ай бұрын
superb quality content🙌
@Eng_wallah
@Eng_wallah 9 ай бұрын
Radhe Radhe bhaiya 🙏🏻🙏🏻
@neetuchaudhary7884
@neetuchaudhary7884 7 ай бұрын
thannnkkkkk youuuuuuu so much bhaiya🤗🤗
@ujjwal_7531
@ujjwal_7531 5 ай бұрын
i did the level order traversal in spiral question using queue vector findSpiral(Node *root) { //Your code here queueq; vectorans; q.push(root); int rand=1; while(!q.empty()){ int size=q.size(); vectortem; for(int i=0;idata); if(temp->left) q.push(temp->left); if(temp->right) q.push(temp->right); } if(rand%2==1) for(int i=size-1;i>=0;--i) ans.push_back(tem[i]); else for(int i=0;i
@vijaysingh-n6p9j
@vijaysingh-n6p9j Ай бұрын
Bahut badiya tha bhaiya
@study-yd6es
@study-yd6es 5 ай бұрын
Amazing Videos keep it up brother
@Harshmishra0007
@Harshmishra0007 8 ай бұрын
Last question Two Nodes are cousin int level(Node *root,int i,int a){ if(root==NULL) return 0; if(root->data==a){ return i; } return max(level(root->left,i+1,a),level(root->right,i+1,a)); } bool f(Node * root,int a,int b,int m,int i){ if(root==NULL) return true; if(root->left && root->right){ if(root->left->data==a && root->right->data==b) return false; else if(root->left->data==b && root->right->data==a) return false; } if(i==m) return true; return (f(root->left,a,b,m,i+1) && f(root->right,a,b,m,i+1)); } bool isCousins(Node *root, int a, int b) { if(!root->left && !root->right) return false; int m=level(root,0,a); int n=level(root,0,b); if(m!=n) return false; else return f(root,a,b,n,0); }
@soumyadeepghosh4428
@soumyadeepghosh4428 5 ай бұрын
// Approach 2 for Problem - 3 (Balanced Binary Tree) class Solution{ public: int height(Node* root) { if(!root) return 0; int leftHeight = height(root->left); int rightHeight = height(root->right); return 1 + max(leftHeight, rightHeight); } bool isBalanced(Node *root) { if(!root) return 1; if(abs(height(root->left)-height(root->right)) > 1) return 0; return isBalanced(root->left) and isBalanced(root->right); } };
@xlr8-Ujjwal
@xlr8-Ujjwal 3 ай бұрын
For those whose program is not passing after test case 1075. Simply add the below line to resolve the edge case ⬇⬇⬇⬇⬇⬇⬇⬇⬇⬇ if(!root ->left && !root ->right) return 0;
@dipakmali9817
@dipakmali9817 7 ай бұрын
Day 154/180 ✅
@Aniruddha_Mukherjee
@Aniruddha_Mukherjee 9 ай бұрын
Good morning Bhaiya ji😍
@vaishnavigoswami5707
@vaishnavigoswami5707 5 ай бұрын
problem 5: to find level of a and b using recursion h =0; and l1=-1;l2=-1;intially void level(Node* root,int a,int b,int h,int&l1,int&l2) { if(root==NULL) return; h++; if(root->left) { if(root->left->data==a) l1=h; if(root->left->data==b) l2 =h; } if(root->right) { if(root->right->data==a) l1=h; if(root->right->data==b) l2 =h; } level(root->left,a,b,h+1,l1,l2); level(root->right,a,b,h+1,l1,l2); }
@ChandanKumar-kt8ku
@ChandanKumar-kt8ku 5 ай бұрын
Congratulations
@YashSaini007
@YashSaini007 9 ай бұрын
Bhaiya Radhe Radhe 🙏
@pankajdubey1123
@pankajdubey1123 8 ай бұрын
Level order Traversal in spiral form : vector findSpiral(Node *root) { //Your code here deque dq; dq.push_back(root); vector ans; int flag=0; int n; Node *temp; while(!dq.empty()) { if(flag%2==0) { n=dq.size(); while(n--) { temp=dq.back(); dq.pop_back(); ans.push_back(temp->data); if(temp->right) dq.push_front(temp->right); if(temp->left) dq.push_front(temp->left); } } else { n=dq.size(); while(n--) { temp=dq.front(); dq.pop_front(); ans.push_back(temp->data); if(temp->left) dq.push_back(temp->left); if(temp->right) dq.push_back(temp->right); } } flag++; } return ans; }
@vivektechtuber204
@vivektechtuber204 9 ай бұрын
Good Morning Bhaiya 🙏
@ankushladani496
@ankushladani496 9 ай бұрын
Thanks bhaiya...❤🎉
@mohit6215
@mohit6215 9 ай бұрын
100k laga do bahiyo
@SanatanaDharmaDaivagnya
@SanatanaDharmaDaivagnya 9 ай бұрын
jai ho bhaiyya
@JayPrajapati-lj8pw
@JayPrajapati-lj8pw 9 ай бұрын
Best content😊😊❤
@aahilkhan4280
@aahilkhan4280 9 ай бұрын
2 questions khud se kr liye bhaiyya ,remaining 3 problems ka algo bhi likh liya tha ,but implement nhi kr paya.
@aadityakumarjha-ju3xg
@aadityakumarjha-ju3xg 9 ай бұрын
Good morning bhaiya
@punitsharma584
@punitsharma584 4 ай бұрын
me in this last question when level came in my mind be like ::level sabke niklenge pr niklenge uske jo khada rhega
@deep_singh01
@deep_singh01 9 ай бұрын
Day 154/180 👍👍
@asad_iliyas
@asad_iliyas 7 ай бұрын
4/5 solved
@itshirdeshk
@itshirdeshk 9 ай бұрын
Day 154 ✅🔥
@allinonemoviesyt
@allinonemoviesyt 9 ай бұрын
1:44:14 Homework bool parents(Node *root, int a, int b){ if(!root) return false; if(root->left && root->right){ if(root->left->data == a && root->right->data == b){ return true; } if(root->left->data == b && root->right->data == a){ return true; } } return parents(root->left,a,b) || parents(root->right,a,b); } void findLevel(Node *root, int a, int b, int level, int &l1 , int&l2){ if(!root){ return; } if(root->left){ if(root->left->data == a){ l1 = level+1; } if(root->left->data == b){ l2 = level+1; } } if(root->right){ if(root->right->data == a){ l1 = level+1; } if(root->right->data == b){ l2 = level+1; } } if(l1 == -1 || l2 == -1) findLevel(root->left,a,b,level+1,l1,l2); if(l1 == -1 || l2 == -1) findLevel(root->right,a,b,level+1,l1,l2); } bool isCousins(Node *root, int a, int b) { int l1 = -1, l2 = -1; findLevel(root,a,b,1,l1,l2); if(l1 != l2) return false; if(parents(root,a,b)){ return false; } return true; }
@utkarshpandey1394
@utkarshpandey1394 4 ай бұрын
nice
@PrathamSinghhAir
@PrathamSinghhAir Ай бұрын
51:58 pe sir ka " dum dum dum dum " 😂
@vijaysingh-n6p9j
@vijaysingh-n6p9j Ай бұрын
bhaiya last vala question bahut hard tha
@ankitchoudhary2914
@ankitchoudhary2914 9 ай бұрын
Chill scene❤❤❤
@pradeepraghu1see
@pradeepraghu1see 9 ай бұрын
till end .
@YASHYADAV-f9i
@YASHYADAV-f9i 2 ай бұрын
bhaiya maja aagya
@akshaythakur4231
@akshaythakur4231 4 ай бұрын
Wow ❤
@fakharabbas9738
@fakharabbas9738 8 ай бұрын
Love U Coder Army❤
@YashSaini007
@YashSaini007 9 ай бұрын
Day 154/180 #180DaysOfCode
@abhishekgupta7709
@abhishekgupta7709 9 ай бұрын
Bhaiya chamka. One request put the Coder army DSA sheet on its website .
@Abhishekkumar-gr5vr
@Abhishekkumar-gr5vr 9 ай бұрын
🔥🔥
@ankitshrestha6481
@ankitshrestha6481 Ай бұрын
// Time O(N) and Space O(N) // Another approach bool isNodes_areCousin(Node* root, int first, int second) { queue list; list.push(root); list.push(nullptr); int currentLevel = 0; int firstLevel = 0; int secondLevel = 0; int parent1 = -1; int parent2 = -1; Node* temp; while (!list.empty()) { temp = list.front(); list.pop(); if (temp == nullptr) { if (list.size() == 0) break; currentLevel++; list.push(nullptr); } else { if (temp->left) { if (temp->left->data == first) { parent1 = temp->data; firstLevel = currentLevel + 1; } if (temp->left->data == second) { parent2 = temp->data; secondLevel = currentLevel + 1; } list.push(temp->left); } if (temp->right) { if (temp->right->data == first) { parent1 = temp->data; firstLevel = currentLevel + 1; } if (temp->right->data == second) { parent2 = temp->data; secondLevel = currentLevel + 1; } list.push(temp->right); } } } return (parent1 != parent2) && (firstLevel == secondLevel); }
@kuldeepparmar9861
@kuldeepparmar9861 8 ай бұрын
chamak gaya last tk
@hiteshsharma5034
@hiteshsharma5034 8 ай бұрын
Bhaiya, Here is my code for Vertical Traversal using pair vector concept, sorting and recursion... class Solution { public: void find(TreeNode* root, int pos, int level, vector &v){ if(root==NULL){ return; } v.push_back(make_pair(pos, make_pair(level, root->val))); find(root->left,pos-1, level+1,v); find(root->right, pos+1, level+1,v); } vector verticalTraversal(TreeNode* root) { vector v; vector ans; if(root==NULL){ return ans; } find(root,0,0,v); sort(v.begin(),v.end()); int prev=v[0].first; vector temp; for(auto x: v){ if(x.first==prev){ temp.push_back(x.second.second); } else{ prev=x.first; ans.push_back(temp); temp.clear(); temp.push_back(x.second.second); } } ans.push_back(temp); return ans; } };
@amorphous8826
@amorphous8826 4 ай бұрын
👍
@Aryan-wl7mc
@Aryan-wl7mc 9 ай бұрын
0:28 Google mai job pakki hai jisne like kiya 😂😂😂
@yashpaunikar671
@yashpaunikar671 8 ай бұрын
bhaiya leetcode ke bhi link attach kr dijiye
@meetdobariya8777
@meetdobariya8777 3 ай бұрын
same code likha cousin ka lekin 1075 pe differnce a raha he
@xlr8-Ujjwal
@xlr8-Ujjwal 3 ай бұрын
Add this line if(!root ->left && !root ->right) return 0;
@fakharabbas9738
@fakharabbas9738 8 ай бұрын
Love U Coder Army
@IR20025
@IR20025 3 ай бұрын
Lec - 104
@pranavmittal9619
@pranavmittal9619 9 ай бұрын
2/5 questions ho gaye lekin vo bhi pehle kar rakhe the
@swarupdwivedy5733
@swarupdwivedy5733 9 ай бұрын
How to prepare DSA with GATE?
@ankitchoudhary2914
@ankitchoudhary2914 9 ай бұрын
done todays classs
@vishnusingh2300
@vishnusingh2300 8 ай бұрын
29:00
@rishuagarwal1523
@rishuagarwal1523 Ай бұрын
leet code 5th number question testcase 1075 is giving wrong output with same code can anybody help
@farhansadik7236
@farhansadik7236 3 ай бұрын
in the spiral traversal i got TLE in leetcode,i cannot figure it out . anyone ?
@letsk9188
@letsk9188 6 ай бұрын
i reach to last
@gateavi
@gateavi 9 ай бұрын
#1
@ShaikSharma
@ShaikSharma Ай бұрын
sir,i have my google interview can i crack if i watch all of your playlist
@anupammishra6514
@anupammishra6514 9 ай бұрын
❤❤
@vivek7187
@vivek7187 9 ай бұрын
🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
@vishnusingh2300
@vishnusingh2300 8 ай бұрын
51.21
@prashantsingh3474
@prashantsingh3474 2 ай бұрын
Level order traversal in spiral form solution of this question using deque... vector findSpiral(Node *root) { dequeq; vectorans; int count=0; q.push_back(root); while(q.empty()!=1){ int qsize=q.size(); for(int i=0;idata); if(temp->right!=NULL){ q.push_front(temp->right); } if(temp->left!=NULL){ q.push_front(temp->left); } } else{ //if count is odd means in tree we move right to left Node* temp=q.front(); q.pop_front(); ans.push_back(temp->data); if(temp->left!=NULL){ q.push_back(temp->left); } if(temp->right!=NULL){ q.push_back(temp->right); } } } count++; } return ans; } If any anyone like my solution then plz like my comment...
@haardikmadaan1644
@haardikmadaan1644 8 ай бұрын
1/5
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 4,7 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 98 МЛН
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 2,7 МЛН
Why is Python 150X slower than C?
10:45
Mehul - Codedamn
Рет қаралды 18 М.
BFS Traversal in Graph | DFS Traversal in Graph
1:19:17
Coder Army
Рет қаралды 19 М.
Quiet Night: Deep Sleep Music with Black Screen - Fall Asleep with Ambient Music
3:05:46
Lecture 63: Binary Tree FAANG Interview Questions || Part-1
1:01:05
CodeHelp - by Babbar
Рет қаралды 424 М.
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 4,7 МЛН