Zig Zag Traversal (LeetCode 103) | Full Solution with visuals and a little trick | Study Algorithms

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 35

  • @meenakshiwadhwa4625
    @meenakshiwadhwa4625 2 місяці тому +1

    Loved the explanation. I like the way you teach. Thanks for great content !!

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

    Congratulations for 10k 🥳

  • @floatingfortress721
    @floatingfortress721 11 місяців тому

    Thanks! After watching this video I was able to solve a similar leetcode question, "Binary Tree Right Side View"

    • @nikoo28
      @nikoo28  10 місяців тому

      that is wonderful

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

    loved the approach. writing how we made queue for level order and then thinking about how we can achieve zig zag pattern with small tweaks. thanks😇

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

      Glad you liked it.

  • @susmitapatil4847
    @susmitapatil4847 8 місяців тому

    Best Explanation. Keep doing good work.

  • @Mydailymutualfundportfolio
    @Mydailymutualfundportfolio 29 днів тому

    Very good explanation 🎉❤

    • @nikoo28
      @nikoo28  28 днів тому

      Thanks for the love!

  • @tanishkaagarwal6750
    @tanishkaagarwal6750 10 місяців тому

    Thank you for the wonderful explanation sir

  • @LalitSingh-nd5vx
    @LalitSingh-nd5vx 11 місяців тому +1

    thanks for awesome explanation !

  • @deepondas5001
    @deepondas5001 9 місяців тому +1

    sir i would say you have great approach and explanation skill if you have done a great marketing then you may have thousands of views

  • @saurabhruikar1131
    @saurabhruikar1131 11 місяців тому

    As always very nice explanation, I would like to suggest a tweak instead of using stack we could simply reverse temporayList at alternate iteration.

    • @nikoo28
      @nikoo28  10 місяців тому

      That's a great idea!

  • @ghanashrim2839
    @ghanashrim2839 Рік тому +4

    The way you approach a new problem is something I'd really like to learn. Amazing explanation as usual.
    What software do you use for video recording and editing? Is this iPad mirrored on the screen and then screen recorded?

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

      I use final cut pro for all the edits, and on iPad I use GoodNotes 5

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

      @@nikoo28 Thank you :)

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

    You are awesome and I love your video explanations!
    My solution was similar but instead of using a stack, I reversed the created list for each level and added it to the final answer list based on the boolean flag. Is it the same as your solution as far as Time and Space complexity, or is it worse?

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

      as long as the time and space complexity is same, doesn't really matter

  • @SibiRanganathL
    @SibiRanganathL 2 місяці тому

    Understood

  • @avinashtiwari4025
    @avinashtiwari4025 10 місяців тому

    can you also explain how we compute the space complexity for this ?

    • @nikoo28
      @nikoo28  9 місяців тому

      space complexity is simply the extra space we use to arrive at our solution. We use a stack, that can have the maximum of n elements in the worst case. Hence, space complexity is O(n)

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

    There is a small mistake in the code while adding popped element from stack to level, which is self explanatory:
    Fixed code:
    TreeNode node = reverseStack.pop();
    level.add(node.val);
    Appreciate your effort, thanks.

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

      Thanks for clearing it out. :)

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

      which line??even the one on screen is running correct

  • @manishasharma-mh7fo
    @manishasharma-mh7fo Рік тому

    sir could u pls make a video on boundary order traversal .

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

      can you give me an example link?

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

    hi sir.
    I seen Ur backtracking video , I commented below that video can u replay for that comment.

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

      How can I help you?

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

      @@nikoo28 I want more default problems with solutions on backtracking algorithm can u Make problems on that ,sir

  • @vibhanshusharma9143
    @vibhanshusharma9143 11 місяців тому

    Bro for instead of stack we can simply reverse a vector
    Batao m puch rha hu😅

  • @ssss22144
    @ssss22144 21 день тому

    please start graph problems also anna

    • @nikoo28
      @nikoo28  21 день тому

      Did you have a look at my playlist on graphs?

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

    Hey Nikhil, I have messaged you on LinkedIn.