Symmetric Tree | leetcode 101 | company tag : Facebook interview question | Python

preview_player
Показать описание
Please like the video, this really motivates us to make more such videos and helps us to grow. thecodingworld is a community which is formed to help fellow student and professionals looking to crack the “coding interviews”.

We love solving and sharing problems which are frequently asked in technical interviews and voted by community at various websites.

✅ For more and upcoming updates join our community

#leetcode #python
Рекомендации по теме
Комментарии
Автор

Fantastic explanation, one can solve this problem without using isMirror function but the beauty is to take concept into consideration and try to relate and understand the concepts learnt from previous problems or here we can solve mirror question from this, hands down of the best solutions I came across, thanks for this. In tough DSA topics like trees, heaps, graphs, DP, greedy, what I observed, as beginner(which I am) you can't really solve it on your own, but learn from few questions itself and try to use the previous concept in next question, the crack is to identify which concept of previous question to be applied here if not then here's the new one learn, coz theory really couldn't help much especially in graphs unless on solves the actual problem.
One simpler way without using isMirror question can be-
def isSymmetric(self, root: Optional[TreeNode]) -> bool:
def dfs(a, b) :
if not a and not b : return True
if not a or not b : return False
if a.val != b.val : return False
return dfs(a.left, b.right) and dfs(a.right, b.left)
return dfs(root.left, root.right)
but the one shown in video is better solution

ritwik_shivam
Автор

whats the purpose of the final 'return leftroot == rightroot' check?

Heroguyjk
Автор

around 9:14 you added return leftroot==rightroot on line 17. Could you elaborate its purpose? What happens when I remove it?

HIDEHUMAN
Автор

Hi! Thanks for the video! I was wondering if you could please clarify why you've returned leftroot == rightroot at the end of the isMirror function if its above conditions are not met? Thanks!

natwong
Автор

Thank you so much! This helped a lot and was the easiest explanation I found.

pearlalmeida
Автор

Fantastic solution man!!! Keep it up and you'll make it into facebook. I don't know why you got disliked though.

soumyajitchatterjee