109. Convert Sorted List to Binary Search Tree || Code + Explanation + Example Walk through

  Рет қаралды 10,446

Code with Alisha

Code with Alisha

3 жыл бұрын

Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

Пікірлер: 27
@ethicalgaming4349
@ethicalgaming4349 Жыл бұрын
Note :- Pass the vector by reference to avoid vector copy in each recursive call.
@vibhavsharma2724
@vibhavsharma2724 Жыл бұрын
Very nice explanation. Thanks🙏🏻
@zeyadalbadawy2245
@zeyadalbadawy2245 10 ай бұрын
the best explaination ever !!
@anaranyabose
@anaranyabose 2 жыл бұрын
Great one!
@masumali8356
@masumali8356 Жыл бұрын
You are the best....masum
@informative180
@informative180 Жыл бұрын
di, u r best..🧡🧡
@santhoshsiva281
@santhoshsiva281 Жыл бұрын
I literally feel fucked up when i didn't get the intution behind this problem.After saw this video i feel good.. You are my lifesaver ❤️
@adityapatil9215
@adityapatil9215 Жыл бұрын
Easy explanation 🙌
@maddycoder1294
@maddycoder1294 Жыл бұрын
nice explanation
@amishajha24
@amishajha24 Жыл бұрын
what is the time complexity
@devbhattacharya153
@devbhattacharya153 2 жыл бұрын
Thnaks a lot didi :)
@baazigaraxcode4994
@baazigaraxcode4994 Жыл бұрын
Love uhh mam ❤️
@BHARATKUMAR-jl1jp
@BHARATKUMAR-jl1jp Жыл бұрын
why this algorithm is working any intuition behind this...?
@ritendrasinghbhadauriya1643
@ritendrasinghbhadauriya1643 7 ай бұрын
Great!
@maragmodh9831
@maragmodh9831 Жыл бұрын
it is not accepted in gfg when the input is 2 i.e. 2 nodes are there please give solution for it
@girishsudhakar1099
@girishsudhakar1099 3 жыл бұрын
Great Explaination Thanks!
@reshmaparveen6679
@reshmaparveen6679 3 жыл бұрын
Great explanation ❤️❤️
@motivationtipsknowledge813
@motivationtipsknowledge813 Жыл бұрын
Vector m store karke thodi na karna hai madam
@SamsIt-hi9gf
@SamsIt-hi9gf 2 ай бұрын
😁😁 mai wahi soch raha hu
@technosujeet
@technosujeet Жыл бұрын
its doesn't seems the optimal solution since you are using extra space
@sauravchandra10
@sauravchandra10 Жыл бұрын
Can we do this without using extra space?
@tanishq2766
@tanishq2766 9 ай бұрын
No imo
@sahilbani7020
@sahilbani7020 Жыл бұрын
easy explanation loved it but takes 416ms of runtime compared to 13ms of top solution and 360mb of memory consumed a better approach would be using slow and fast pointer method to find the middle of the linked list thanks for this video TreeNode* fun(ListNode* l, ListNode* r) { ListNode *s=l, *f=l; if(l==r) return NULL; while(f!=r && f->next!=r) { s=s->next; f=f->next->next; } TreeNode* t=new TreeNode(s->val); t->left=fun(l,s); t->right=fun(s->next,r); return t; } TreeNode* sortedListToBST(ListNode* head) { if(head==NULL) return NULL; if(head->next==NULL) return new TreeNode(head->val); return fun(head, NULL); }
@ethicalgaming4349
@ethicalgaming4349 Жыл бұрын
You can reduce this time(416ms to 32ms) if u pass the vector by reference.
@sahilbani7020
@sahilbani7020 Жыл бұрын
@@ethicalgaming4349 yes bro but creating a vector will take space complexity of O(N), you can simply manipulate your list by slow and fast pointers as mentioned in my code
@priyanshubora1938
@priyanshubora1938 25 күн бұрын
noice
@user-xg7hi5mh3g
@user-xg7hi5mh3g Жыл бұрын
Great Video thank u so much for your Efforts& time . How to implement this in c# The first part when i get defined the node from this recursiv method ..?
Binary Search Animated
7:00
Dreams of Code
Рет қаралды 27 М.
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 49 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 7 МЛН
Doing This Instead Of Studying.. 😳
00:12
Jojo Sim
Рет қаралды 19 МЛН
Leetcode 894. All Possible Full Binary Trees
29:08
Code with Alisha
Рет қаралды 3,9 М.
LeetCode 637. Average of Levels in Binary Tree || Code + explanation
9:12
AVL Trees Simply Explained
11:53
Maaneth De Silva
Рет қаралды 121 М.
Easy Google Coding Interview With Ben Awad
28:00
Clément Mihailescu
Рет қаралды 1 МЛН
Convert sorted array to binary search tree | LeetCode 108 | Easy
6:50
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 633 М.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 265 М.