LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal (Algorithm Explained)

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


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

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

Most of this explanation just bounced over my head! Hey Nick, can you please explain the algorithm a bit more clearly, before getting into the code. Because end of the day, logic and derivation of the solution is what matters right, and coding will be easy after that! Thanks for the video though.

ArjunKalidas
Автор

You can convert the in order array to a hash map storing {inorder val : index} to avoid looping through the in order array each time

trung.n
Автор

Not sure how he has so much followers. The solutions are either taken from solution or reporduced from memory without any explanations.

Aditya-rmbl
Автор

I find that the main time cost in this solution is from the for loop search part, you can reduce the time cost by using a hashmap for inorder element search.

zmanneverdie
Автор

Your solutions always explain the intuition behind the solution.

AkshayKumar-xhob
Автор

So finally you did this problem. I watched yesterday's live stream when you were solving this.

saiyamkumarsingh
Автор

Is there a way to improve look up for the inIndex?

evgeni-nabokov
Автор

Can you please also tell us the time and space complexity when making these video? Just subscribed. Yours is easier to understand than solution in discussion lol

brovet
Автор

Thanks Nick. You are awesome! Constructing Binary Tree from PostOrder and Inorder is very similar to this problem. In PostOrder, the sequence is "left, right, center", which means we need to loop PostOrder array from the end. Recursive inputs to root.left and root.right will also differ accordingly (but very similar to this video).

vinothbornwin
Автор

Your solution is always very concise. I was coding it and got all the index mangled up. Thanks for the video!

kittwwang
Автор

Great video!!! I took a while to understand the concept. Can you tell what is the time and space complexity for this approach?

suyashsorte
Автор

But in other sites like gfg they are passing preStart as prestart+1 in both root->left and root->right and still giving correct output. Can you explain why?

-ei
Автор

Good explanation of preorder, inorder and postorder

FitnessChaos
Автор

so u knoe how to reverse a linked list, but do u knoe how to design a large scale software system

lowkey_anp
Автор

If I am a novice to trees, what can you recommend? I couldn't understand the video.

emansrnme
Автор

Thanks for the video, it helped me. Do you know what would be the approach if the array would have repeated elements? (or the work around)

darod
Автор

Why code in this video get stack over flow?

카이트-cy
Автор

Just subscribed cause you said you can grow as you get more subscribers LOL We will help your channel grow, you help us learn data structures and algorithms. I appreciate you teaching us these concepts.

User_Unknown_Anonymous
Автор

In line 29, where does inIndex - inStart + 1 come from? In other words, how do you map inorder index to preorder index?

calfland
Автор

Nick, can you share your 2ms submission? Thanks

rodanm