LeetCode 101: Symmetric Tree - Interview Prep Ep 22

preview_player
Показать описание

Amazon Coding Interview Question: Symmetric Tree (LeetCode #101)

Coding Interview Gist:

Without Preparation 😎 Before Interview = Ready To Be Grilled 😭 During Interview

This is one of Amazon's most commonly asked questions according to LeetCode. It's also seen in interviews for these companies: Uber/Microsoft/Twitter per LeetCode.

Solution explained:
A simple intuition flows out to a recursive solution: we just check if the two given nodes at any structurally equivalent positions are equal, if not, return false.
Looking at the given API signature, it's not possible to realize this, so we'll just write a helper function ourselves to do so.

⭐ Support my channel and connect with me:

// TOOLS THAT I USE:

// MY FAVORITE BOOKS:

My ENTIRE Programming Equipment and Computer Science Bookshelf:

And make sure you subscribe to my channel!

Your comments/thoughts/questions/advice will be greatly appreciated!

#softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures
Рекомендации по теме
Комментарии
Автор

This is the first video I dont understand from your video list.

chenlee
Автор

would be great if you could add recursive call stack visual, just like other videos

pil
Автор

Thank you for the great video. For the line 20, why we used "return left == right"?

staythecoursenote
Автор

Please explain the base condition, why it has been taken?

pankhurigupta
Автор

what all i have to do crack internships in top companies, please list the topics in will be very thankful to you

ArpitDhamija
Автор

Python recursion and iterative method:

class Solution:
def isSymmetric(self, root: TreeNode) -> bool:
# # The simplest method is recursion
# if root is None: return True
# def dfs(p, q):
# if p is None and q is None: return True
# if p is None or q is None: return False
# if p.val != q.val: return False
# return dfs(p.left, q.right) and dfs(p.right, q.left)
# return dfs(root.left, root.right)

# BFS
if root is None: return True
queue = collections.deque([root.left, root.right])
while queue:
p = queue.popleft()
q = queue.popleft()
if p is None and q is None: continue
if p is None or q is None: return False
if p.val != q.val: return False
queue.extend([p.left, q.right, p.right, q.left])

return True

hyli