Binary Tree Zigzag or Spiral Level Order Traversal | Tree Data Structure playlist C++ | Hello World

Поділитися
Вставка
  • Опубліковано 12 лис 2024

КОМЕНТАРІ • 33

  • @nitinjha4863
    @nitinjha4863 Рік тому

    Thank you so much sir !
    Your explanation for level order and zig zag traversal question make me understand the logic clearly.

  • @rajchinagundi7498
    @rajchinagundi7498 2 роки тому +4

    I did it on my own after watching your level order video, this felt like a piece of cake

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому

      Thanks a lot Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @cr7johnChan
    @cr7johnChan 2 роки тому +1

    aapke wajah se yeh meh khud kar paya hoon,graph karne ke baad yeh playlist bijli ki speed se ho raha hai

  • @UnKnown-id7ih
    @UnKnown-id7ih 2 роки тому +1

    Bahot badiya explanation bhiya. 🙏🙏

  • @jalpanpatel5570
    @jalpanpatel5570 Рік тому +2

    Sir apka solution optimize solution nahi he issme riverse vala extra time lagta he.

  • @73-sarthakpandey25
    @73-sarthakpandey25 3 роки тому +5

    best explanation and code keep it up

    • @HelloWorldbyprince
      @HelloWorldbyprince  3 роки тому +1

      Thanks 😌
      Keep sharing my channel with your friends and colleagues

  • @kanandnaik5677
    @kanandnaik5677 2 роки тому

    dhanyavad bhai

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому

      Keep learning dost
      Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @prakashbarui5070
    @prakashbarui5070 3 роки тому +4

    vaiiia aap regular vedo dala ki jiye

  • @anonymous090
    @anonymous090 2 роки тому

    Thank you Bhaiya

  • @akshaykumar192
    @akshaykumar192 Рік тому

    Thanks

  • @princemaurya3165
    @princemaurya3165 Рік тому

    thanks bro
    🙃

  • @tabrezahmed1000
    @tabrezahmed1000 Рік тому +1

    Why cant we use flag and do the operation of inserting into queue in opposite direction

  • @MANISHKUMAR-vn1yh
    @MANISHKUMAR-vn1yh 2 роки тому

    thanks Buddy 😁😁😁😁😁😁

  • @llo.welc_me
    @llo.welc_me 2 роки тому +1

    ai se hi bhaia pen paper se samjhaie
    best hein rathen than slide

  • @vitaminprotein2217
    @vitaminprotein2217 2 роки тому

    maine queue mei jb root push kr rhe the jbhi reverse krke daala by phele right ko fir left ko ,pr iss sol se sre given test case satisfy ho rhe pr bhut sre edge cases miss ho rhe plz highlight the mistake
    vector zigzagLevelOrder(TreeNode* root) {
    int count=1;
    //bfs traversal
    vectorans;
    //edge case
    if(!root) return {};
    queueq;
    q.push(root);
    while(!q.empty()){
    count++;
    vectortemp;
    int size=q.size();
    for(int i=0;iright)q.push(node->right);
    if(node->left)q.push(node->left);
    }
    else{
    if(node->left)q.push(node->left);
    if(node->right)q.push(node->right);
    }
    temp.push_back(node->val);
    count++;
    }
    ans.push_back(temp);
    }
    return ans;

  • @vanivaishnavi3916
    @vanivaishnavi3916 3 роки тому +6

    Waoooò

  • @icarus4716
    @icarus4716 Місяць тому

    better and less calc needed
    bool flag
    each time !flag

  • @sarthakgupta1102
    @sarthakgupta1102 2 роки тому

    hey in the question they are asking to return a vector not a vector of vector so how to deal with it?

    • @anubhav5623
      @anubhav5623 2 роки тому +1

      use
      for(auto i : data)
      {
      ans.push_back(i);
      }
      and then
      return the ans.

  • @jayeshnayee6735
    @jayeshnayee6735 2 роки тому

    vector to std::vector return ans; how solve this problem

  • @satyamsrivastava1871
    @satyamsrivastava1871 2 роки тому

    sir issme kya problem aaya hai
    vector zigzagLevelOrder(TreeNode* root) {
    vector ans;
    queue q;
    q.push(root);
    int level=0;
    if(root==NULL)
    return ans;
    while(1)
    {
    int size=q.size();
    if(size==0)
    return ans;
    level++;
    vectordata;
    while(size>0){
    TreeNode *temp=q.front();
    q.pop();
    data.push_back(temp->val);
    if(level%2==0)
    {
    if(temp->right!=NULL)
    q.push(temp->right);
    if(temp->left!=NULL)
    q.push(temp->left);
    }
    else
    {
    if(temp->left!=NULL)
    q.push(temp->left);
    if(temp->right!=NULL)
    q.push(temp->right);
    }

    size--;
    }

    ans.push_back(data);

    }

    return ans;
    }
    @Hello World