LeetCode Day 20 - Binary Search Tree from Preorder Traversal

preview_player
Показать описание
Binary Search Tree is an important data structure and you should be able to construct it from an array. I'm showing O(N^2) and then O(N) solution starting at 8:49

Subscribe for more educational videos on algorithms, coding interviews and competitive programming.

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

Wow Errichto! You explained it beautifully. One thing i like the most is the way you explain how to approach a problem.
Keep making such videos!

harishrawat
Автор

The way this guy explains is plain superb !! Thanks

psn
Автор

Really appreciate you starting with the simpler solution first. Helps build intuition for the more complex solutions

unhappysisyphus
Автор

hell yes we need more of these tutorials btw great explanation

CSBVASAMMANJUNATHKASHIRAM
Автор

Another outstanding video Errichto!! Additional tutorials on BST, BFS and DFS would be great.

jimwoodward
Автор

Thank you very much, didn't understand the code of O(n) solution, but drawing at the end of the video helped me to get the idea, now I can try to code it myself

uzdik.student
Автор

Fantastic video, I tried to wrap my head around the more advanced solution (2nd one) with various explanations, and your video finally did it!

ianpan
Автор

yaa we want BST tutorial, it will be a great entertainment to learn from you bruh, take love ✨

k_co_KristidharPandit
Автор

This is the best walkthrough I've seen on tree problems. Thanks!

brovet
Автор

This was amazing explanation of binary search trees!! I love you

ganumba
Автор

It is fun watching you write these. I hope they give you some harder ones though, it is more fun when you don't know the answer right away.

CarrotCakeMake
Автор

Please keep the explanation (step by step + drawing) like in this video's end part. It's really helpful. Even if the problem is simple.

flamendless
Автор

The problem here is you return a reference of a local variable to outer scope but the local variable will be deleted if it goes out of inner scope.
P/s: great content :)

bacuongcao
Автор

I solved using 3 methods.
1)Using stack
2)recursion
3)sorting preorder to get inorder then constructing from them.

RAJPATEL-nmnz
Автор

Hi Errichto . On Behalf of the coding community I would like to request if you could continue the LeetCode Challenge so that we can learn from it. It will be helpful for all of us as we had our previous Leetcode Monthly Challenge.
Thanks

ChandraShekhar-bycd
Автор

I really enjoyed it like a show!
Go for these trees tutorial including recursion. Thanks <3

BedoEbied
Автор

A tutorial on various trees, like AVL tree, red-black tree, segment tree would be extremely helpful. There are very rare good tutorials on them

priyank
Автор

for my solution i used a stack to save the visited nodes, first i start by adding the root to the stack and for each element from the sequence if it's less than the top i do top->left = current. otherwise, i pop from the while the element values are small than the current value, eventually, there will be at least an element in the stack (at the end i add current to the right of the last element that had a value smaller than current)

AllmohtarifeBlogspot
Автор

The linear solution is very elegant. For some reason, my brain worked better with a stack than a recursion. I put on stack the first root (the result) and then if the next value is less than the stack top I put it on the stack, if not I pop from the stack to the moment it's either empty or the top is not less than the value and put again the new node on the stack.

andreykarayvansky
Автор

Please Take Leetcode 30 days challenge every month!! you are a gem!

hemantranjan