Construct Binary Tree from Inorder and Preorder Traversal | Love Babbar DSA Sheet | Amazon 🔥 | GFG

#tree #competitiveprogramming #coding #dsa
Hey Guys in this video I have explained with code how we can solve the problem 'Construct Binary Tree from Inorder and Preorder Traversal'.
Array question Playlist = • Love Babbar DSA 450 Qu...
String question Playlist = • Love Babbar DSA 450 Qu...
Searching and Sorting question Playlist = • Love Babbar DSA 450 Qu...
Binary Tree question Playlist = • Love Babbar DSA 450 Qu...
Dynamic Programming question Playlist = • Love Babbar DSA 450 Qu...
RoadMap of Web Development = • 🔴 Web Development Road...
Roadmap for Dynamic Programming = • Complete Roadmap for D...
Great Strategy to solve DSA = • Great Strategy to solv...
My Journey to 5 star at codechef = • My Journey to 5 Star a...
Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
Follow us on Instagram:
Shailesh Yogendra : / shaileshyogendra
Yogesh Yogendra : / i_am_yogesh_here
Follow us on LinkedIn:
Yogesh Yogendra : / yogesh-yogendra-26bbb518a
Shailesh Yogendra : / shailesh-yogendra-8b13...
Hope you like it. Comment if you have any doubt
LIKE | SHARE | SUBSCRIBE

Пікірлер: 56

  • @145_aratrikaroy8
    @145_aratrikaroy83 жыл бұрын

    Thank you so much for these videos. You have helped an unimaginable deal to give me the zeal to pretty much start coding. I usually don't comment at all, but you totally deserve it. I can't thank you enough!

  • @himanshusarad6491
    @himanshusarad64913 жыл бұрын

    kasam se bro...pichle 10 ghante se samajhne ki try kr rha ..tysm for this explanation.

  • @debdhritiroy6868
    @debdhritiroy68683 жыл бұрын

    The most important reason for which i was stuck with this was an assumption I missed, which was of not assuming duplicates... If there were two nodes with same value, searching or using map would be futile.. Would appreciate if anyone could find the solution where duplicates could be allowed

  • @vishaldange2163
    @vishaldange21633 жыл бұрын

    calling nodes as "Bande Log" is awesome

  • @RajputAnkit11

    @RajputAnkit11

    2 жыл бұрын

    haha

  • @kabilanm9206
    @kabilanm92063 жыл бұрын

    Bro..I am continuously doing dsa450 sheet , is it usefull in cracking Interview rounds ..please tell bro..🙏

  • @lalitkumarmehta1721
    @lalitkumarmehta17213 жыл бұрын

    Thanks bro nice explanation, and keep solving the sheet questions👏

  • @gauravgarg2814
    @gauravgarg28143 жыл бұрын

    bhai acha smj aya ..thanks for this video

  • @muskansawa2802
    @muskansawa28023 жыл бұрын

    Thanks for the video!

  • @krishanudev4023
    @krishanudev40233 жыл бұрын

    I always watch your video trust me u r d best..... I have a doubt though why you did m.clear() and also idx = 0(you had already declared it in line number 63) in line number 81 and 80 respectively. 😊😊😊😊😊😊😊😊

  • @CodeLibrary

    @CodeLibrary

    3 жыл бұрын

    when i was solving i thought that the T is also given i.e testcases ..... so for each testcases you have to make idx=0 and clear map because we have taken both of them globally....... If T is not given then no need to do that

  • @krishanudev4023

    @krishanudev4023

    3 жыл бұрын

    @@CodeLibrary 🙏🙏

  • @kumarsandiproy1548
    @kumarsandiproy15482 жыл бұрын

    u r so good in teaching

  • @oqant0424
    @oqant04242 жыл бұрын

    Thank u so much... very useful

  • @harshitavyas7497
    @harshitavyas74972 жыл бұрын

    AMAZING EXPLANATION

  • @chanduchandrakanth5131
    @chanduchandrakanth51312 жыл бұрын

    Amazing 🔥

  • @rajatkapoor2815
    @rajatkapoor28153 жыл бұрын

    nice explanation bro

  • @narendratechguy7140
    @narendratechguy71403 жыл бұрын

    y are u passing inorder array if map is being used

  • @yes_daily_motivation
    @yes_daily_motivation2 жыл бұрын

    Will it work for duplicate values?

  • @prasannapm3220
    @prasannapm32202 жыл бұрын

    thanks!

  • @shivaraju8405
    @shivaraju84053 жыл бұрын

    You need to add a condition at 66 to check if idx doesnt exceed ub limit. if(lb > ub || idx >= ub) return null; this has to be added

  • @rajatmaheshwari4656

    @rajatmaheshwari4656

    2 жыл бұрын

    it's still working without the condition in gfg

  • @viditsharma3929
    @viditsharma39293 жыл бұрын

    isme distinct toh mention nhi toh unordered map fail nhi karega repeating element k liye?

  • @livelypooja

    @livelypooja

    Жыл бұрын

    Haan submit ni hoga code.maine isliye search Kiya element in order me frm lb to ub

  • @ratnadeepbhattacharya3237
    @ratnadeepbhattacharya32373 жыл бұрын

    bro i think if (lb == ub) condition is redundent....

  • @atuldwivedi7677
    @atuldwivedi76773 жыл бұрын

    Samaj nahi aaya par sunkar achha laga 😂😂

  • @AinasDiaries

    @AinasDiaries

    2 жыл бұрын

    +1

  • @mohdarshad9427
    @mohdarshad94272 жыл бұрын

    it is memorized solution not more than that

  • @karunakarreddythavanam4335
    @karunakarreddythavanam43353 жыл бұрын

    Writing the code from scratch would be of great help rather than explaining the code what is written already

  • @yashvardhan6001
    @yashvardhan60012 жыл бұрын

    it is showing segmentation fault!!

  • @jaydalsaniya6986
    @jaydalsaniya69862 жыл бұрын

    Map tabhi kaam ayega jab all the nodes have distinct values .

  • @dheerajsharma8784
    @dheerajsharma87842 жыл бұрын

    Code of the video: TreeNode* solve(vector& preorder, vector& inorder, int start, int end) { if (start > end) return nullptr; TreeNode* node = new TreeNode(preorder[index++]); int mid = mp[node->val]; node->left = solve(preorder, inorder, start, mid - 1); node->right = solve(preorder, inorder, mid + 1, end); return node; } TreeNode* buildTree(vector& preorder, vector& inorder) { int n = preorder.size(); for (int i = 0; i mp[inorder[i]] = i; } return solve(preorder, inorder, 0, n - 1); }

  • @diveshrajput572
    @diveshrajput5723 жыл бұрын

    Bhai bhut shaandar

  • @mirdulswarup9065
    @mirdulswarup9065 Жыл бұрын

    Bhai please bta do idx kyun global lia h, jahan global nhi lia wahan with reference lia h. Mai 5 days se ispr atka hua hu please tell me

  • @CodeLibrary

    @CodeLibrary

    Жыл бұрын

    yaa both options are correct. You can take global or by reference as well.

  • @mirdulswarup9065

    @mirdulswarup9065

    Жыл бұрын

    @@CodeLibrary bhai please please yeh bta do local variable without reference kyun ni le skte

  • @yashgupta-fk3zc
    @yashgupta-fk3zc2 жыл бұрын

    bhaiya paar inorder to humesa sorted form mai hota hai??

  • @sanketgharatkar5379

    @sanketgharatkar5379

    2 жыл бұрын

    bhai vo sirif BST me hota haii

  • @yashgupta-fk3zc

    @yashgupta-fk3zc

    2 жыл бұрын

    @@sanketgharatkar5379 thnx bro

  • @AnkitMishra-mz4xt
    @AnkitMishra-mz4xt2 жыл бұрын

    Can anyone tell me Why idx has to be declared globally? And if sent as arguments then why its sent as reference?

  • @ankitdwivedi4213

    @ankitdwivedi4213

    2 жыл бұрын

    because we need to update the value of the variable in each recursion stack, so address is passed .

  • @alokhemrom
    @alokhemrom Жыл бұрын

    Using map will not pass the test cases with duplicate value:- Try this code:- int idx=0; int search(int in[],int k,int l){ for(int i=l;1;i++) if(k==in[i]) return i; } Node* buildTree1(int in[],int pre[],int l,int r){ if(l>r) return NULL; Node* p=new Node(pre[idx++]); if(l==r) return p; int mid=search(in,p->data,l); p->left=buildTree1(in,pre,l,mid-1); p->right=buildTree1(in,pre,mid+1,r); return p; } Node* buildTree(int in[],int pre[], int n) { // Code here return buildTree1(in,pre,0,n-1); }

  • @fahadabdullah687
    @fahadabdullah6872 жыл бұрын

    akshay kumar meme at 6:28 😃

  • @VedPrakash-zo7bu
    @VedPrakash-zo7bu Жыл бұрын

    idk whats wrong with geek for geek , it gives error after 60 test cases

  • @bhakodiasolankiakash4312

    @bhakodiasolankiakash4312

    11 ай бұрын

    It's probably because the test case is having duplicate node

  • @jatinkashyap9986

    @jatinkashyap9986

    Ай бұрын

    Instead of using map use that in[] and make a function which will find the value of that node from that In array and return the position

  • @deepanshukumar7290
    @deepanshukumar72903 жыл бұрын

    run time error aa rha hai

  • @goyaldeekshant
    @goyaldeekshant3 жыл бұрын

    tough one:

  • @deepanshukumar7290
    @deepanshukumar72903 жыл бұрын

    apne submit bhi nhi krke dekhaya

  • @CodeLibrary

    @CodeLibrary

    3 жыл бұрын

    Watch till end....I have submitted the Solution..have a look

  • @pranshusahijwani6313
    @pranshusahijwani63132 жыл бұрын

    if(start==end) return root; This line is unnecessary

  • @sumitjindal1115
    @sumitjindal11153 жыл бұрын

    it is showing segmentation fault!!

  • @yashvardhan6001

    @yashvardhan6001

    2 жыл бұрын

    bro yeh problem kaise solve hui

Келесі