First I have completed all DSA series and now conclude this is Greatest ever DSA series to exist on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂ Thanks you.
Thank you sir :), for making tree simple and understandable . I would like to highlight one point : Mapping solution will give wrong answer in case of duplicated nodes..... in such case , we can optimize findpos() function by checking from inStart to inEND .. int findpos(int in[],int x,int n,int s,int e) { for(int i=s;i
The code mentioned in the video doesn't passes updated testcases --> So here is the updated code --> class Solution{ private: int Findposition(int in[] ,int inorderStart , int inorderEnd , int element ,int n){ for(int i = inorderStart ; i=n || inorderStart>inorderEnd){ return NULL ; } int element = pre[index++] ; // At every interation index is increasing Node* root = new Node(element); int position = Findposition(in , inorderStart , inorderEnd ,element, n); root->left = solve(in , pre , index , inorderStart , position-1 ,n); root->right = solve(in , pre , index , position+1 , inorderEnd ,n); return root ; } public: Node* buildTree(int in[],int pre[], int n) { // Code here int preorderindex = 0 ; //Pre order is NLR so First element is root . Node* ans = solve(in , pre , preorderindex , 0 , n-1 , n ); return ans ; }
Question 1 Test case 54 fails after addition of new test case Solution: Can't use maps. Use findPosition function and pass inorderStart and inorderEnd as arguments and not n(size). This happens because elements might be repeated.
There is something wrong with this concept let me just clear it up . When you check for the location of the element in the inorder array you need not check it's location by traversing in the whole array instead , you need to check for the element in the required portion . In this case check for the element from in[inOrderStartIndex] to in[inOrderEndIndex] and you will just be fine
@@PriyanshuSrivastava11fig sure here it is. class Solution{ public: int findposition(int element , int in[] , int start , int end) { for(int i = start ; i = n || inorder_start > inorder_end) { return NULL; } int element = pre[preorderindex]; Node* root = new Node(element); int position = findposition(element,in ,inorder_start , inorder_end); preorderindex++; root->left = solve(in,pre,n,preorderindex, inorder_start , position - 1); root-> right = solve(in , pre , n , preorderindex, position + 1 , inorder_end);
You are doing literally a very good job. I got to understand many concepts easily after watching your videos. Trees are very well explained. Many Thanks.
first question is explained very deeply but one more condition is also added on gfg that the values of root can be repeated thanks for the quality content
Wahh... Bhaiya mann gya aapko.. Kya consistency ha aapkee.. Ham ek video dekh nhi paarahe.. Aur aapke... New video... Aa rahe.. Ha bhaut saahi bhaiya.. Bass.. Aise hee consistentsy ham bhi continue kar paaye... Great bhaiya really great fan of you!!!!!! 🤗🤗
A Very WELL EXPLANATION wala Video and Insane amount of Effort of Love Bhaiya is clearly vivble and For that Again and Again Explanation Thank you bhaiya
wah bhaiyaa ..another an exciting session i understood every thing from this session thanks bhiyaa for providing free of cost DSA course...loves the most...content and your teaching technique is so optimistic...thanks again
Sir apke efforts to wakai sir excellent and ek aur best cheez ki aap scratch se har cheez samjhate hai........and sir salute to your consistency........💯💯
Sir ive been part of this course from the start And the amount of knowledge that i ve gained is just inexpressable When i saw that it was 7 am on morning and you were shooting i was forced to comment here Thankyou so much Whatever i am in DSA is due to you I owe you alot
bhai dono me O(1) hogi na. Map ki key already pata h toh value toh yuhi nikal jaegi aur mp.find() use krne ki need nhi kyuki map toh bana hi saari entries se hai, key toh pakka hogi hi.
Basically if there are two equal elements in the inorder array , then it won't work and the testcases also are updated now, so the small change will be instead of looking in the entire inorder array, look in the part from instart to inend.
One suggestion bhaiya... We don't wanna get demotivated...so contest ke bhi solutions practice krwaiyega please......And company specific category bhi ki like kis site se kaun si kaun si company specific pdhna h... Interviewbit ,gfg,...etc...Amazon, Microsoft,google nd aur bhi
code link from 66 lecture to end is not available sir , plzz upload the link the of code link. thank you from the bottom of my heart sir for making a beautiful series for us 😍😍
Bhai Lecture 66 onwards code ko github mai push kyo nhi kar rhe ho? Repo se code samajna easy rehta hai. during videos hum code samaj sakte and then after completion of video hum code repo se notedown kar sakte hai. so pls push code from lecture 66 onwards in github repo.
In these questions, maps is useful in cases that have no equal values of nodes. but if there are... then you've to go for the first approach whose TC is o(n^2). Correct me if I'm wrong If you're trying with maps and gfg is not accepting, do it by the 1st approach
Updated map solution for question - Construct Tree from Inorder & Preorder Intuition - Use Queue inside map to store the duplicates in the tree. class Solution{ public: void createMap(int in[], int n, map &nodeToIndex){ for (int i=0; i= n || inOrderStart > inOrderEnd){ return NULL; } //storing the node of preOrder (NLR) int element = pre[index++]; Node* root = new Node(element);
//find the node in inorder (LNR) int position = nodeToIndex[element].front(); nodeToIndex[element].pop(); //recursive call for left and right root->left = solve(in, pre, n, index, inOrderStart, position-1, nodeToIndex); root->right = solve(in, pre, n, index, position+1, inOrderEnd, nodeToIndex); return root; } Node* buildTree(int in[],int pre[], int n) { int preOrderIndex = 0; map nodeToIndex; createMap(in, n, nodeToIndex); Node* ans = solve(in, pre, n, preOrderIndex, 0, n-1, nodeToIndex); return ans; } };
Thank you so much bhaiya, before it I have been read 2,3 time but my concept was not clear but in first attempt I got 100℅ understanding of construct tree, ab mai DS se diprate ni ho rha😃ni to 4th sem me aa kar lgta tha khi CSE le kar galti to ni kr diye...
# for those who stuck in test case 53 # there are dublicate values use map below is full code:- ---------------------------------------------------------------------------------- class Solution{ public: int find(int in[],int n,int element){ for(int i=0;iend || ind >=n) return NULL; int element = pre[ind++]; Node* root=new Node(element); // int pos=find(in,n,element); int pos = mp[element].front(); mp[element].pop(); root->left=make(in,pre,n,ind,start,pos-1,mp); root->right = make(in,pre,n,ind,pos+1,end,mp); return root; } public: Node* buildTree(int in[],int pre[], int n) { map mp; for(int i=0;i
Sir this is an amazing and very helpfull play list it helped me a lot . There is only one thing i want to known is where is the link for codes after lecture 65
Can some tell me how in root left and right after giving range positions it is extracting the elements from inorder array? We are only finding the position of element from in order arr and passing the positions to recursion but how it is allocating the root left and right from the I order arr??
3 things I learn when I see this videos one is dsa concepts and other is consistency and commitment.
Absolutely right
Hey are u there? actually i am not able to find the codes on the github link after lec 65..i think they are missing
@@khushisrivastava357bro itna to khud try kar
consistency is important bro
30:15 You clearly have a strong understanding about where the students could get stuck. Much love
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exist on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇♂ Thanks you.
bro 65th lecture ke bad GitHub par code links nhi hai ky ??
Thank you sir :), for making tree simple and understandable .
I would like to highlight one point :
Mapping solution will give wrong answer in case of duplicated nodes..... in such case , we can optimize findpos() function by checking from inStart to inEND ..
int findpos(int in[],int x,int n,int s,int e)
{
for(int i=s;i
Yes you're right
The code mentioned in the video doesn't passes updated testcases -->
So here is the updated code -->
class Solution{
private:
int Findposition(int in[] ,int inorderStart , int inorderEnd , int element ,int n){
for(int i = inorderStart ; i=n || inorderStart>inorderEnd){
return NULL ;
}
int element = pre[index++] ; // At every interation index is increasing
Node* root = new Node(element);
int position = Findposition(in , inorderStart , inorderEnd ,element, n);
root->left = solve(in , pre , index , inorderStart , position-1 ,n);
root->right = solve(in , pre , index , position+1 , inorderEnd ,n);
return root ;
}
public:
Node* buildTree(int in[],int pre[], int n)
{
// Code here
int preorderindex = 0 ; //Pre order is NLR so First element is root .
Node* ans = solve(in , pre , preorderindex , 0 , n-1 , n );
return ans ;
}
Really helpful, thanks
Thanks
it really helps, i was soo confused.
thanks...
@@vimalrai2092 for which question
can u tell us what you have change in this code??
because i have see this couple of time but , i could not catch it??
Question 1 Test case 54 fails after addition of new test case
Solution:
Can't use maps. Use findPosition function and pass inorderStart and inorderEnd as arguments and not n(size). This happens because elements might be repeated.
There is something wrong with this concept let me just clear it up . When you check for the location of the element in the inorder array you need not check it's location by traversing in the whole array instead , you need to check for the element in the required portion . In this case check for the element from in[inOrderStartIndex] to in[inOrderEndIndex] and you will just be fine
Thanks Bro it works.
@@shwetpatel2712 please share the updated code. I'm not able to figure it out how to pass 54th test case using map
@@PriyanshuSrivastava11fig
sure here it is.
class Solution{
public:
int findposition(int element , int in[] , int start , int end)
{
for(int i = start ; i = n || inorder_start > inorder_end)
{
return NULL;
}
int element = pre[preorderindex];
Node* root = new Node(element);
int position = findposition(element,in ,inorder_start , inorder_end);
preorderindex++;
root->left = solve(in,pre,n,preorderindex, inorder_start , position - 1);
root-> right = solve(in , pre , n , preorderindex, position + 1 , inorder_end);
return root;
}
Node* buildTree(int in[],int pre[], int n)
{
int preorderindex = 0;
Node* temp = solve(in,pre,n, preorderindex, 0 , n-1);
return temp;
}
};
bro what would happend if elements are repeated in between inroderStart and inorderEnd
Best course!
Best teacher!
*Best time to learn!* 🔥
mid course me kon coad dana band kar data hai ghanta best teacher
You are doing literally a very good job. I got to understand many concepts easily after watching your videos. Trees are very well explained. Many Thanks.
first question is explained very deeply but one more condition is also added on gfg that the values of root can be repeated
thanks for the quality content
for repeated nodes Just use map mpp and find element index by using {mpp[element].front()} then pop the queue
Best course ever🔥
consistency++;
Best DSA course and consistency ++...Thank u so much for your effort❤
The best DSA course ✨❤️
Wahh... Bhaiya mann gya aapko.. Kya consistency ha aapkee.. Ham ek video dekh nhi paarahe.. Aur aapke... New video... Aa rahe.. Ha bhaut saahi bhaiya..
Bass.. Aise hee consistentsy ham bhi continue kar paaye... Great bhaiya really great fan of you!!!!!! 🤗🤗
A Very WELL EXPLANATION wala Video and Insane amount of Effort of Love Bhaiya is clearly vivble and For that Again and Again Explanation Thank you bhaiya
Here we can also use unordered map (T.C - O(1)) as we don't need data to be sorted, so the overall t.c will be O(n)
Bro it will not work if we have dublicate values in array like (1 2 3 4 3)
wah bhaiyaa ..another an exciting session i understood every thing from this session thanks bhiyaa for providing free of cost DSA course...loves the most...content and your teaching technique is so optimistic...thanks again
Bhaiya ki knowledge, video uploading me consistency, or way of explanation top notch hai!🔥🔥🔥
Totally agreed
Sir apke efforts to wakai sir excellent and ek aur best cheez ki aap scratch se har cheez samjhate hai........and sir salute to your consistency........💯💯
Best dsa course I have ever seen
Amazing observation bro on the inorder to postorder question. I have never thought it that way.
Q1
TC = O(n^2)
SC = O(1)
Q1(if hashmap is used), use unordered_map
TC = O(n)
SC = O(n)
Q2
TC = O(n^2)
SC = O(1)
Q2(if hashmap is used)
TC = O(n)
SC = O(n)
hii are you complete this course
Great Efforts Sir....I think who wants to learn tree this is the platform
One of the best teacher || mentor. Thank you so much bhaiya for this course literally the best course.
Sir ive been part of this course from the start
And the amount of knowledge that i ve gained is just inexpressable
When i saw that it was 7 am on morning and you were shooting i was forced to comment here
Thankyou so much
Whatever i am in DSA is due to you
I owe you alot
Awesome!! The best DSA anyone can teach!!
Best explanation!!! You make solutions look so simple.
Best DSA course on youtube !
It is the best dsa course in the you tube bhaiya carry on we all are with you 🌹🌹
Thanks you sir, excellent content, no one can explain like you from basic 🙏 god bless you
words are not enough to express our gratitude towards you.. Thank you bhaiya
Sir many many thanks to you
You're an inspiration , I've referred this playlist to all my friends.
Your dedication is next level sir
in first question u used map for optimisation which have complexity O(logn), shouldn't we use unordered_map for O(1) complexity ??
Yes
bhai dono me O(1) hogi na. Map ki key already pata h toh value toh yuhi nikal jaegi aur mp.find() use krne ki need nhi kyuki map toh bana hi saari entries se hai, key toh pakka hogi hi.
@@sahilchhabra2391 I didn't got your point
But even inserting into map also takes O(log n)
So it definitely adds into time complexity
@@Coder_DhruvArora oh I forgot about the insertion complexity for ordinary map 😅, ya ya u got that right
I used to get scared from some of questions including these But now .....Huhh! . All thanks to you bhaiya
Basically if there are two equal elements in the inorder array , then it won't work and the testcases also are updated now, so the small change will be instead of looking in the entire inorder array, look in the part from instart to inend.
bro 65th lecture ke bad GitHub par code links nhi hai ky ??
Can you give advice on what to do after seeing the solution of a problem you've never seen before and don't know how to code..?
The best best best and best course ever
ab ye question mai kabhi bhi nhi bhulne wala😁
One suggestion bhaiya... We don't wanna get demotivated...so contest ke bhi solutions practice krwaiyega please......And company specific category bhi ki like kis site se kaun si kaun si company specific pdhna h... Interviewbit ,gfg,...etc...Amazon, Microsoft,google nd aur bhi
code link from 66 lecture to end is not available sir , plzz upload the link the of code link.
thank you from the bottom of my heart sir for making a beautiful series for us 😍😍
After this course Knowledge will be like knowledge= INT_MAX;
bhaiya, we can also solve it using unordered map, which can reduce the TC to O(n).
lecture 66 onwards, the codes are not available on the github link mentioned in description. Where can i get those codes, does anyone have any idea?
Bhai Lecture 66 onwards code ko github mai push kyo nhi kar rhe ho? Repo se code samajna easy rehta hai. during videos hum code samaj sakte and then after completion of video hum code repo se notedown kar sakte hai. so pls push code from lecture 66 onwards in github repo.
is Source-code of lecture 66 onwards available anywhere ?
did you got any sourse where codes are there this lecture onwards?
Can we construct from postorder and inorder by using pre and inorder function by reversing postorder vector
thank you bhaiya .. you are doing regularly hardwork to complete this course ..
bahut bahut dhanybad..
❤💘💘💘💘
Deadline Seriously Le Rhe Ho Kya Bhaiyya😂
Consistant Level OP😁🥰
I just solving this question from ur DSA sheet n got this video notification ♥️♥️💯
Shaandar video hai bhaiya 👍👍👍
east or west babbar bhaiyya best
Best explanation compared to others...!
here in solve function why we sent map by address, because i try to sent by value and it gave me TLE
In these questions, maps is useful in cases that have no equal values of nodes. but if there are... then you've to go for the first approach whose TC is o(n^2). Correct me if I'm wrong
If you're trying with maps and gfg is not accepting, do it by the 1st approach
use map of int ,queue insted
Op consistency bhaiya 👍🔥🔥🔥
Thank you bhaiya
Maza aa gya questions solve krke ✌️✌️
kabhi kabhi lagta hain humse to jyada app mehenat karte hain bhaiay...!!
Sir can you please update your Github Repository.
Updated map solution for question - Construct Tree from Inorder & Preorder
Intuition - Use Queue inside map to store the duplicates in the tree.
class Solution{
public:
void createMap(int in[], int n, map &nodeToIndex){
for (int i=0; i= n || inOrderStart > inOrderEnd){
return NULL;
}
//storing the node of preOrder (NLR)
int element = pre[index++];
Node* root = new Node(element);
//find the node in inorder (LNR)
int position = nodeToIndex[element].front();
nodeToIndex[element].pop();
//recursive call for left and right
root->left = solve(in, pre, n, index, inOrderStart, position-1, nodeToIndex);
root->right = solve(in, pre, n, index, position+1, inOrderEnd, nodeToIndex);
return root;
}
Node* buildTree(int in[],int pre[], int n)
{
int preOrderIndex = 0;
map nodeToIndex;
createMap(in, n, nodeToIndex);
Node* ans = solve(in, pre, n, preOrderIndex, 0, n-1, nodeToIndex);
return ans;
}
};
bhaiya aap best ho
Present bhaiya
Consistency op 🔥🔥🔥
Commenting for better reach
u make everything simple
Bhaiya agar unordered_map use krege to time complexity O(n) ho jayegi
I think if we use unordered map instead of map then our time complexity will be more better as it have T.C of O(1)
NO bro, if we use map then if any number is repeating then we won't be able to make right tree.
@@roshangupta629 but what will it effect? repeation se kya hoga usme ye set thodi h
we can use mutlimap instead of map here@@roshangupta629
consistency op... Thanks for the beautiful content...Just enjoyed going through the lectures one by one... 😁
mehnat lag raha hai bhai tum enjoy kaise kar le rahe ho.🥺🥺🥺🥺
Dedication 😱💯💯
If you are reading this comment so I want to tell you that you have not provided the code in github from lecture 66
Any reason for that?😢
Thankyou So much bhaiya going great
Great Work👋👋
Rough algorithm
node build_tree :
if(preorder_start > preorder_end || inorder_start > inorder_end) return null;
node = new node(preorder[preorder_start])
node_inorder_pos = map[node->val]
preorder_range_left = preorder_start -> node_inorder_pos - inorder_start - 1
preorder_range_right = preorder_range_left_end + 1, preorder_end
inorder_range_left = inorder_start-> node_inorder_pos - 1,
inorder_range_right = node_inorder_pos + 1 -> inorder_end
node->left = build_tree(preorder_range_left, inorder_range_left)
node->right = build_tree(preorder_range_right, inorder_range_right)
return node
Love _Consistency_ Babbar!
Awesome Explanation!
Thank you so much bhaiya, before it I have been read 2,3 time but my concept was not clear but in first attempt I got 100℅ understanding of construct tree, ab mai DS se diprate ni ho rha😃ni to 4th sem me aa kar lgta tha khi CSE le kar galti to ni kr diye...
Attendance marked 👍👍👍
consistency 🔥🔥🔥
Thank you sir 😊
# for those who stuck in test case 53
# there are dublicate values
use map
below is full code:-
----------------------------------------------------------------------------------
class Solution{
public:
int find(int in[],int n,int element){
for(int i=0;iend || ind >=n) return NULL;
int element = pre[ind++];
Node* root=new Node(element);
// int pos=find(in,n,element);
int pos = mp[element].front();
mp[element].pop();
root->left=make(in,pre,n,ind,start,pos-1,mp);
root->right = make(in,pre,n,ind,pos+1,end,mp);
return root;
}
public:
Node* buildTree(int in[],int pre[], int n)
{
map mp;
for(int i=0;i
Lecture was amazing brother
Great consistency sir💯💯. Thank youu vry much!!
Please anyone provide the source code of all the questions solved in this lecture. i am not able to find anywhere.
sir your find index function is wrong because it itrates whole inorder array , where it should go from start to end in that particular call.
Commenting for better reach !!
consistency++. PBC on the go.
Which company are you in, I mean how are u managing preparation and job?
I am not able to find codes of any lecture after lecture 65 on github... What to do?
bhaiya bhut badia padate hoo aap
Bhaiya internship par video banao with DSA busted course as resource 🤩💥💥 {{{5 month left for on campus Internship}}}
Best course ever
consistency++;
you made me feel the traversal of tree
bhaiya bhut axcha samjhate ho
great work and effort
Bhaiya consistency
keep coding and sharing errors as well as solutions to the error
Was waiting for this one......💯💯💯💯
I am not able to find the code after lec 65 on github ..can u please upload them too!
There is a request to you that pls do zoom screen vwhen you present system screen so We can se easily on coding time.
Sir this is an amazing and very helpfull play list it helped me a lot . There is only one thing i want to known is where is the link for codes after lecture 65
+1
Loved your efforts. Thank you bhaiya
Simply Love You Bhaiya 💗💗
bhaijaan please yhi c++ ke tarah 1 JAVA ka placement dsa course le aaye WITHOUT ANY ONE SHOT on youtube
Can some tell me how in root left and right after giving range positions it is extracting the elements from inorder array? We are only finding the position of element from in order arr and passing the positions to recursion but how it is allocating the root left and right from the I order arr??
Great series , very helpful .
keep growing bhaiya. You do wonderful for us
Great lecture as always😍