Same Tree (LeetCode 100) | Full solution with visuals and animations | Study Algorithms

preview_player
Показать описание
Two trees even if they are different can result in a same traversal result. This happens because of the non-linear structure of the tree data structure. A neat little trick can be applied to the level order traversal technique to determine if two trees are exactly the same. Watch this video to understand how you can take advantage of the actual structure of a tree node and arrive at a solution.

Chapters:
00:00 - Intro
00:52 - Problem Statement and Description
02:58 - What exactly are same trees?
05:50 - A trick with level order traversal
09:02 - Dry-run of Code
12:57 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

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

No one has solved this in this way.Thank you!!

shrirangjoshi
Автор

I am a fan of BFS. Thanks Man for the solution. :)

SahayaPaduvaiRaja
Автор

Thanks, you were able to simplify the problem and its solution for me :)

floatingfortress
Автор

Bro please make video on Question Number 110. Balanced Binary Tree.and your Teaching technique is so good. Please make video urjently because my Amazon interview schedule in next week

AniketWaghmare-qiwm
Автор

u should do the dryrun by taking values, on each step what values it is taking

pro
Автор

Can you do a tutorial on the recusive solution? figiured out the itreative solution but I am still a little bit confused on how the recusive solution works.

brentdaniels
Автор

sir please make playlist on recursion this concept is root for all advance concept of dsa

mdshafiuddin
Автор

Which one is better? recursive or iterative? Recursive solutions comes naturally to for trees usually.

LOUD_Ruffian
Автор

Please do solution in python or make a poll :(

leetcode
Автор

I don't think I understand how the tree works.

In the first test case the trees are q = [1, 2, 3] and p = [1, 2, 3] and if I write:
return q.val == p.val and q.left == p.left and q.right == p.right, the output is False???

Also if I try just return q (for science), I would expect the output to be the tree [1, 2, 3], but instead the output is True?? What the fuck.

How do these damn trees work?!?

philandros
visit shbcf.ru