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

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

Nick White

4 года назад

80,154 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@_sf_editz1870
@_sf_editz1870 - 15.12.2023 12:37

Coolll easiest explanation on internet

Ответить
@tusharsingh7926
@tusharsingh7926 - 26.11.2023 13:15

Thank You So Much for this wonderful video.......🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

Ответить
@HridayGandhi-ix3gl
@HridayGandhi-ix3gl - 02.10.2023 13:51

ur explanations are not clear and understandable you should be first clear urself and then teach others

Ответить
@nikakondra5321
@nikakondra5321 - 03.09.2023 20:49

Thank you Nick!

Ответить
@user-vu8jp3si2r
@user-vu8jp3si2r - 16.03.2023 07:08

Why code in this video get stack over flow?

Ответить
@abhinavrana5356
@abhinavrana5356 - 13.06.2022 10:14

Pretty stupid explanation tbh

Ответить
@aaronlong1298
@aaronlong1298 - 20.11.2021 03:33

His attitude is kind of the worse, It's extremely hard to get through this because of it. I can feel condescension permeating this video.

Ответить
@ajaytyagi3018
@ajaytyagi3018 - 02.11.2021 03:02

f

Ответить
@vinothborn2win
@vinothborn2win - 19.10.2021 02:26

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).

Ответить
@Aditya-rm3bl
@Aditya-rm3bl - 02.08.2021 12:58

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

Ответить
@lazycoder1910
@lazycoder1910 - 19.06.2021 14:29

Thanks for all ur work!

Ответить
@Vishal-joshi1998
@Vishal-joshi1998 - 08.06.2021 11:21

complex

Ответить
@son0funiverse
@son0funiverse - 05.06.2021 21:15

Yeah, this was a doozy

Ответить
@cathywei8842
@cathywei8842 - 07.05.2021 16:50

Thank you ! really helpful!

Ответить
@AkshayKumar-xh2ob
@AkshayKumar-xh2ob - 06.04.2021 23:00

Your solutions always explain the intuition behind the solution.

Ответить
@FitnessChaos
@FitnessChaos - 11.03.2021 05:47

Good explanation of preorder, inorder and postorder

Ответить
@karankanojiya7672
@karankanojiya7672 - 03.03.2021 06:48

Beauty Nick !!

Ответить
@rodanm
@rodanm - 15.02.2021 20:11

Nick, can you share your 2ms submission? Thanks

Ответить
@Hgh38
@Hgh38 - 26.12.2020 22:38

Anyone think question is hard? I even saw this video and I still don’t get it.

Ответить
@FINSuojeluskunta
@FINSuojeluskunta - 22.12.2020 18:41

Sorry but this video sucks. This seems like some crappy memorization over understanding approach.

Ответить
@kittwwang
@kittwwang - 11.12.2020 00:27

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

Ответить
@trung.n
@trung.n - 09.11.2020 08:18

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

Ответить
@ShubhamVerma-cn7bc
@ShubhamVerma-cn7bc - 03.09.2020 21:51

Nice Video, gr8 explaination

Ответить
@yv6358
@yv6358 - 03.09.2020 16:07

you get my stuff. Watch and subscribe so that I can grow my thing. What is he referring to

Ответить
@mandar.vaidya
@mandar.vaidya - 30.08.2020 12:35

thanks nick

Ответить
@demidrek-heyward
@demidrek-heyward - 29.08.2020 08:00

not sure why people dislike these videos?

Ответить
@user-bi4gg9he7v
@user-bi4gg9he7v - 19.08.2020 16:05

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?

Ответить
@sophiezhang6516
@sophiezhang6516 - 17.08.2020 22:56

good explaination!

Ответить
@vk1618
@vk1618 - 15.08.2020 06:06

Review

Ответить
@pankajrathi
@pankajrathi - 31.07.2020 16:20

Kevin >> Nick

Ответить
@rasikachavan7290
@rasikachavan7290 - 28.07.2020 23:27

Thanks for simplifying the problem!! Can you tell time complexity and space complexity of this?

Ответить
@evgeni-nabokov
@evgeni-nabokov - 28.07.2020 02:53

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

Ответить
@adamberry7536
@adamberry7536 - 23.07.2020 02:16

You can save the value and index lookup for the inorder in a hashmap to avoid the for loop in your recursive stack.

Ответить
@zahash1045
@zahash1045 - 08.07.2020 18:42

could you please zoom out a little further, please? Who wants to see what's being typed on the screen anyways

Ответить
@sarthaksrivastav3408
@sarthaksrivastav3408 - 06.07.2020 08:06

(inIndex - inStart) is basically leftSubTreeCount which is here only 1 as there is only 1 node i.e. 9 on the left side of 3. So, that's why preorder start value will be preStart + leftSubtreeCount + 1 here.

Ответить
@anirudhatalmale5575
@anirudhatalmale5575 - 01.07.2020 16:49

Awesome explanation. Thanks

Ответить
@alaukikpant9720
@alaukikpant9720 - 23.06.2020 18:48

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

Ответить
@jamesgeng7815
@jamesgeng7815 - 15.06.2020 04:34

Man! It does not look like you in this video, you must have drive some vodka...

Ответить
@JoshRibakoff
@JoshRibakoff - 26.05.2020 02:25

I think the `preStart>preorder.length-1` check is not needed at all. For the left downward calls, eventually inEnd will reach 0 & it will base case out because inEnd decreases & inStart does not. For the right downward calls, inStart will base case out because it increases & inEnd does not. Also FYI it sort of feels like you're "just" reading us the solutions shown on Leetcode during some parts of the video (breaking eye contact & reading the other person's answer as a reference/running into various errors/erratic explanations). Overall its a great video, this is just some constructive criticism.

Ответить
@arianphilips5777
@arianphilips5777 - 21.05.2020 03:21

It took me 1 hour to do this problem, and you just did it in 11 minutes DAM

Ответить
@jiwonkang5329
@jiwonkang5329 - 13.05.2020 07:27

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.

Ответить
@suyashsorte
@suyashsorte - 13.05.2020 00:39

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

Ответить
@ArjunKalidas
@ArjunKalidas - 24.04.2020 08:16

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.

Ответить
@akrmh9934
@akrmh9934 - 22.04.2020 19:06

good explanation but the screen is far....i can't see obviously

Ответить
@calfland79
@calfland79 - 13.04.2020 05:55

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

Ответить
@MrThepratik
@MrThepratik - 09.04.2020 01:05

nailed it . thanks for the clear explaination

Ответить
@darod6098
@darod6098 - 14.03.2020 21:00

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)

Ответить
@trinhta9410
@trinhta9410 - 04.03.2020 03:53

it is hard to understand the formula for the prestart of the right nodes. My solution was passing prestart as reference and increment its by 1 for every-time a node is created. Thank you for your video.

Ответить
@zakaryzhi5054
@zakaryzhi5054 - 11.02.2020 16:13

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.

Ответить