Symmetric Tree (Leetcode - 101) - (Amazon, Microsoft, Mentor (Siemens)) : Explanation ➕ Live Coding

  Рет қаралды 4,320

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 21
@hameedmulani21
@hameedmulani21 Жыл бұрын
Bhai will be popular/famous soon! So, starting me hi bhai se pehchan karlo through comment! 😊😁 📈👨‍💻 I'll be happy for him! if he becomes popular.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Hameed ❤️ Means a lot
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
True yaar
@harsh.jain22
@harsh.jain22 Жыл бұрын
I used the String approach you explained in previous video : -----------> class Solution { String leftSubtreeString(TreeNode root){ if(root == null) return "N"; return Integer.toString(root.val) + leftSubtreeString(root.left) + leftSubtreeString(root.right); } String rightSubtreeString(TreeNode root){ if(root == null) return "N"; return Integer.toString(root.val) + rightSubtreeString(root.right) + rightSubtreeString(root.left); } public boolean isSymmetric(TreeNode root) { String leftSubtree = leftSubtreeString(root.left); String rightSubtree = rightSubtreeString(root.right); return leftSubtree.equals(rightSubtree); } }
@venkatarohitpotnuru38
@venkatarohitpotnuru38 4 ай бұрын
Bhaiyya achha hai
@komalkrishna7836
@komalkrishna7836 Жыл бұрын
Very well explained!! Thank you 😊 Java code public boolean isSymmetric(TreeNode root) { if(root == null) return true; return check(root.left, root.right); } public boolean check(TreeNode lnode, TreeNode rnode){ if(lnode == null && rnode == null) return true; if(lnode == null || rnode == null) return false; if(lnode.val != rnode.val) return false; return check(lnode.left, rnode.right) && check(lnode.right, rnode.left); }
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
Feels great, I am improving day by day. Thanks
@tanishqdawar5545
@tanishqdawar5545 Жыл бұрын
i swear apki videoss mai ye question ekdam shai kar rha tha bass ek choti si mistake thi ajise hi apki video explanation dekhi ho gaya solve question
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Awesome 🙏😇
@JJ-tp2dd
@JJ-tp2dd Жыл бұрын
Thanks, bhai. Below is the Java Implementation : TC O(N) and space Complexity O(logN) i.e. height of tree (for the recursive stack used) class Solution { private boolean solve(TreeNode l, TreeNode r) { // both of them are null if(l == null && r == null) { return true; } // only one of them is null if(l == null || r == null) { return false; } // the values are different if(l.val != r.val) { return false; } return solve(l.left, r.right) && solve(l.right, r.left); } public boolean isSymmetric(TreeNode root) { return solve(root.left, root.right); } }
@debjeetmukherjee4591
@debjeetmukherjee4591 10 ай бұрын
Giving wrong Answer .. . class Solution { boolean check(TreeNode l,TreeNode r) { if(l==null || r==null) { return false; } if(l==null && r==null) { return true; } if(l.val != r.val) { return false; } return check(l.left, r.right) && check(l.right, r.left); } public boolean isSymmetric(TreeNode root) { if (root == null) { return true; } return check(root.left,root.right); } }
@aadityabuchale15
@aadityabuchale15 Жыл бұрын
Java Code if any one want : class Solution { boolean check( TreeNode left , TreeNode right ){ if( left == null && right == null) // if both are null then it is symmetric return true; if( left == null || right == null ) // if one of them is true means it is not symmetric return false; boolean oneSide = check( left.left , right.right); // checking one side of tree boolean anotherSide = check( left.right , right.left); //checking anotherSide of tree if( (left.val == right.val) && oneSide && anotherSide ) return true; // if values are equal and both recursive conditions are equal then also true return false; } public boolean isSymmetric(TreeNode root) { if (root == null) return true; return check( root.left , root.right); } }
@shloksuman8164
@shloksuman8164 Жыл бұрын
thanks for this simple explanation, it became very clear to me
@codestorywithMIK
@codestorywithMIK Жыл бұрын
So glad
@Shubham_Singh841
@Shubham_Singh841 Жыл бұрын
Great
@MaheshPatil-of1zy
@MaheshPatil-of1zy 9 ай бұрын
how to build logic for these type of tree questions? means which approach can we use? how to decide that?
@venkatarohitpotnuru38
@venkatarohitpotnuru38 4 ай бұрын
Bhaiyya ka videos dekheke concept build karna hoga
@elakstein
@elakstein Жыл бұрын
Udemy se konsa course kar rahe bhai.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Recently i did Elastic search and Go
@guptashashwat
@guptashashwat Жыл бұрын
@@codestorywithMIK Go ka course kaisa hai bhai? Lene layak hai? I want to learn GO
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Yes Go is good. Very simple and elegant one
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
УДИВИЛ ВСЕХ СВОИМ УХОДОМ!😳 #shorts
00:49