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

  Рет қаралды 7,051

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Actual Problem: leetcode.com/problems/binary-...
Chapters:
00:00 - Intro
00:47 - Problem Statement and Description
03:35 - Using level order traversal for zig-zag
08:54 - Dry-run of Code
13:38 - Final Thoughts
📚 Links to topics I talk about in the video:
Level Order Traversal: • Level order traversal ...
Stack Data Structure: • Stack Data Structure e...
Tree Data Structure: • Understanding Tree Dat...
📘 A text based explanation is available at: studyalgorithms.com
Code on Github: github.com/nikoo28/java-solut...
Test-cases on Github: github.com/nikoo28/java-solut...
📖 Reference Books:
Starting Learn to Code: amzn.to/36pU0JO
Favorite book to understand algorithms: amzn.to/39w3YLS
Favorite book for data structures: amzn.to/3oAVBTk
Get started for interview preparation: amzn.to/39ysbkJ
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
🎥 My Recording Gear:
Recording Light: amzn.to/3pAqh8O
Microphone: amzn.to/2MCX7qU
Recording Camera: amzn.to/3alg9Ky
Tablet to sketch and draw: amzn.to/3pM6Bi4
Surface Pen: amzn.to/3pv6tTs
Laptop to edit videos: amzn.to/2LYpMqn
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Follow on Twitter at: / studyalgorithms
Follow on Tumblr at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#leetcode #programming #interview

Пікірлер: 27
@akshayrajsingh555
@akshayrajsingh555 Жыл бұрын
Congratulations for 10k 🥳
@LalitSingh-nd5vx
@LalitSingh-nd5vx 5 ай бұрын
thanks for awesome explanation !
@susmitapatil4847
@susmitapatil4847 2 ай бұрын
Best Explanation. Keep doing good work.
@tanishkaagarwal6750
@tanishkaagarwal6750 4 ай бұрын
Thank you for the wonderful explanation sir
@floatingfortress721
@floatingfortress721 5 ай бұрын
Thanks! After watching this video I was able to solve a similar leetcode question, "Binary Tree Right Side View"
@nikoo28
@nikoo28 4 ай бұрын
that is wonderful
@himanshisingh9
@himanshisingh9 7 ай бұрын
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 6 ай бұрын
Glad you liked it.
@deepondas5001
@deepondas5001 3 ай бұрын
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 6 ай бұрын
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 4 ай бұрын
That's a great idea!
@ghanashrim2839
@ghanashrim2839 Жыл бұрын
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 :)
@avinashtiwari4025
@avinashtiwari4025 4 ай бұрын
can you also explain how we compute the space complexity for this ?
@nikoo28
@nikoo28 4 ай бұрын
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)
@manishasharma-mh7fo
@manishasharma-mh7fo Жыл бұрын
sir could u pls make a video on boundary order traversal .
@nikoo28
@nikoo28 Жыл бұрын
can you give me an example link?
@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 11 ай бұрын
which line??even the one on screen is running correct
@mjeevan2408
@mjeevan2408 Жыл бұрын
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 5 ай бұрын
Bro for instead of stack we can simply reverse a vector Batao m puch rha hu😅
@pragyaprashar7165
@pragyaprashar7165 8 ай бұрын
Hey Nikhil, I have messaged you on LinkedIn.
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 163 МЛН
Русалка
01:00
История одного вокалиста
Рет қаралды 5 МЛН
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 137 МЛН
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 67 МЛН
DSA Phir se with Sumeet | Leetcode 6 | Zigzag Conversion
17:54
Pepcoding
Рет қаралды 4,7 М.
Two Sum | LeetCode 1 | JavaScript | Easy
13:20
Gordon Zhu
Рет қаралды 8 М.
6. Zigzag Conversion | Leetcode | Medium | Java | String | Google
8:29
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 617 М.
Leetcode Problem Solving #6 - Zigzag Conversion | Tamil
10:02
CS in Tamil
Рет қаралды 5 М.
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 163 МЛН