Trick for spiral matrix traversal

  Рет қаралды 195,670

Techdose

Techdose

4 жыл бұрын

This video explains a very frequently asked question in programming interviews which is to print the given matrix (either square or rectangular matrix) in a spiral way. My friend was asked this question in microsoft group fly round. This video contains the explanation of the logic and an elegant trick or hack to solve this question elegantly. CODE LINK is given below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
CODE LINK: drive.google.com/open?id=1akK...

Пікірлер: 556
@pankajrathi
@pankajrathi 3 жыл бұрын
I have seen few other videos but everyone started explaining with the written code. You were the only one who has explained the approach and then started coding. Explained in a very brilliant manner. More power to you.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@PsSarvna
@PsSarvna 3 жыл бұрын
Yesterday, I got rejected in final round for not solving this problem. That's why I'm here 🙋‍♂️.
@techdose4u
@techdose4u 3 жыл бұрын
Now you know it :)
@rashidixit1168
@rashidixit1168 3 жыл бұрын
Same here bro
@techdose4u
@techdose4u 3 жыл бұрын
@@rashidixit1168 :o
@titanofchaos
@titanofchaos 3 жыл бұрын
which comapny?
@PsSarvna
@PsSarvna 3 жыл бұрын
@@titanofchaos Zoho On-Campus
@premsainoolu8290
@premsainoolu8290 2 жыл бұрын
I have watched many videos on this ,but none of them had given clarity for me..but this one gives me the understand of the trick in easy way
@OscarMartinez-nt6zn
@OscarMartinez-nt6zn Жыл бұрын
Thanks for this explanation; it was so clear! It's beautiful to see how a seemingly complicated problem can be explained in a simple way if the problem is broken down into simple steps as you did!
@doersstuff8067
@doersstuff8067 2 жыл бұрын
before watching this video I couldn't believe that i can understand this approach to this problem. You made it so simple.
@mugdhabasak9335
@mugdhabasak9335 3 жыл бұрын
the simplicity of this solution just blew my mind!
@anantpatel8342
@anantpatel8342 4 жыл бұрын
Amazing bro, awesome video. I was watching on my browser, I logged in just to like your video. You made it so simple man. WOW
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@mohitpandya_2228
@mohitpandya_2228 Жыл бұрын
The best explanation on entire youtube!! Hats off sir! 💜
@akanshamishra6776
@akanshamishra6776 Жыл бұрын
It's my first time to be on this channel and I immediately subscribe this channel. This is the best explanation I got. It was easy to understand as logic was already explained before the code.
@laharibangaru3756
@laharibangaru3756 3 жыл бұрын
Wow, code is just like saying normally in English. Nowhere felt it was difficult. That was really a very good way of explaining sir. Thanks for making it easy. 👏
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@jinysong2990
@jinysong2990 3 жыл бұрын
you explained it soooo well! I was stuck and my code was getting insanely complicated. I watched your video and maybe 5 seconds in I had a new way of approaching the problem. So I stopped watching and coded everything on my own based on your hint of an approach, and it worked!!! Runtime: 40 ms Memory Usage: 13.6 MB
@techdose4u
@techdose4u 3 жыл бұрын
Nice 😊
@lakshaysingla2754
@lakshaysingla2754 2 жыл бұрын
3D spiral ata hai kya aapko?
@hhhhhhhhh963
@hhhhhhhhh963 2 жыл бұрын
@@lakshaysingla2754 Mujhe toh 2D he Tough laga
@lakshaysingla2754
@lakshaysingla2754 2 жыл бұрын
@@hhhhhhhhh963 yaar wo to hai but hamare college walo ne 3D spiral de diya test mai karne ko
@saunaknandi1814
@saunaknandi1814 2 жыл бұрын
@Jiny Song on which platform you run the program
@JuanGarcia-rq9hz
@JuanGarcia-rq9hz 3 жыл бұрын
amazing video dude, i was needing this but filling the array from right to left. With your video and some of reverse engineering for my case makes this method works very well . your teaching style just blow up my mind i understood everything you tell, you explain in a simply way .even if i speak an other language just keep making this good work ^^
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@kshitizagarwal8389
@kshitizagarwal8389 2 жыл бұрын
OMG this one is amazing man! Highly appriciated. Got me another way of approaching a problem Thanks. Kudos!
@techykush7192
@techykush7192 3 жыл бұрын
i really like your teaching style ,mind blowing u understood us in a simplest form i have seen ever thanks bhaiya 😊😊
@techdose4u
@techdose4u 3 жыл бұрын
Welcome 😃
@chandraprabhat3496
@chandraprabhat3496 2 жыл бұрын
To traverse matrix in any manner we just need to write nested loops (their count will be equal to total turns) ... Only we need to work on defining the loop variable limits only in terms of number of rows, columns and a variable i .
@kritikasingh4698
@kritikasingh4698 2 жыл бұрын
this is such a beautiful explanation that it cleared my doubt in one go. can't thank you enough for this. keep up the good work .lots of respect.
@sugandhm2666
@sugandhm2666 2 жыл бұрын
Bro you teach the approach and logic so well. Many KZbinrs simply jump into coding without explanations
@sureshgarine
@sureshgarine 2 жыл бұрын
wow! what a wonderful explanation. saying thanks is not enough. please continue the good work for the community
@techdose4u
@techdose4u 2 жыл бұрын
Thanks
@ARIFAHMAD-cj4xk
@ARIFAHMAD-cj4xk Жыл бұрын
Thank you, this is the easiest approach i have seen so far and well explained
@divyanshudwivedi3756
@divyanshudwivedi3756 Жыл бұрын
You made it look very easy . Thanks a lot !
@JayJayJay007
@JayJayJay007 Жыл бұрын
Brilliant explanation, very easy to understand and remember the approach. Big thanks!
@SenthilKumar-nt2tk
@SenthilKumar-nt2tk 3 жыл бұрын
U r such an awesome person ..thank you for this code... god bless you
@avinash7786
@avinash7786 4 жыл бұрын
Literally you are a great person..What an explanation..Thank you soooo much.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@natureone5617
@natureone5617 3 жыл бұрын
what a lovely explanation and a very easy approach to traverse a matrix spirally thank you and loved to watch more videos
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@hackytech7494
@hackytech7494 4 жыл бұрын
You are fantastic, such a mind blowing explanation ..please keep it up ..coding gets very easy by listening to your explanation and Thankyou so much
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@akankshitadutta8842
@akankshitadutta8842 Жыл бұрын
Very good explanation !! I watched many other videos but this is by far the most apt explanation. The code seemed easy post understanding the concept you so very well explained!
@rajatagrawal1999
@rajatagrawal1999 2 жыл бұрын
The way u have explained the concept is amazing. I coded it without any help. Thanks :)
@mrcgaming9306
@mrcgaming9306 2 жыл бұрын
this is best explanation I have ever seen Thank you so much sir. I understood everything
@sindhubandaru55
@sindhubandaru55 3 жыл бұрын
Thank you for your explanation . After watching this I'm able write the program without copying the code
@MsHappygirl26
@MsHappygirl26 2 жыл бұрын
Thank you so much! So easy to understand when you explain it!
@techdose4u
@techdose4u 2 жыл бұрын
Welcome :)
@jisanson
@jisanson 9 ай бұрын
the best explanation i've found for the problem, thank you!
@rahulvarma3004
@rahulvarma3004 3 жыл бұрын
very clear explanation .......If i don't understand any leetcode problem, the first thing I do is to search in your channel.....Thank you so much.....keep posting more solutions
@dayanandraut5660
@dayanandraut5660 3 жыл бұрын
I was solving this question using the same idea you have presented here. I was getting some failed test cases. I used if statements. Saw your video. Used if...elseif statement. Code ran like a rocket. Thanks for explaining the solution is the easiest way possible
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@ritiksrivastava9069
@ritiksrivastava9069 Жыл бұрын
It helps me to explore the new way of solving the problem..
@ShreyaSingh-vr9qi
@ShreyaSingh-vr9qi 4 жыл бұрын
Your all video tutorials are awesome !!
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@kambalavijay6800
@kambalavijay6800 3 жыл бұрын
I never thought it is as simple as this
@techdose4u
@techdose4u 3 жыл бұрын
Nice :)
@irisi3308
@irisi3308 3 жыл бұрын
Best explanation ever. I usually don't comment on videos, but this is the best!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks for letting me know :)
@maheshvenkat1349
@maheshvenkat1349 2 жыл бұрын
Great job in explaining in the reasonable speed and in an very understanding manner! :clap
@kingmaker9082
@kingmaker9082 2 жыл бұрын
a huge thanks to you . everything is perfect. you saved my day
@akki4083
@akki4083 3 жыл бұрын
Thanks Bro. You made this question really easy. I was really frustrated. Thanks for the help.
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@anantagarwal863
@anantagarwal863 4 жыл бұрын
Amazing, the trick made the problem very easy
@kianaahmadi193
@kianaahmadi193 2 жыл бұрын
Thank u , you explained the problem very well, i was struggling to understand the solution before watching your video
@shravniwakde1754
@shravniwakde1754 2 жыл бұрын
You explained in such a beautiful manner thank you...!!!
@techdose4u
@techdose4u 2 жыл бұрын
Welcome :)
@paragroy5359
@paragroy5359 2 жыл бұрын
Thanks a lot for the video....clear and awesome explanation.....keep making such videos They are really helpful
@prajwalpatil9395
@prajwalpatil9395 3 жыл бұрын
Soo good ! Legends always make it look soo easy !
@techdose4u
@techdose4u 3 жыл бұрын
Thanks 😅
@tanujmishra2313
@tanujmishra2313 3 жыл бұрын
Your Explanation is really nice. I want to add something to the solution Since we are printing the string in a fixed pattern, We can do it so without using variable dir while ( top < down || left < right ) 1.Print left to right & top++ 2.Print top to down & right-- 3.Print right to left & down-- 4.Print down to top & left++ Thanks for the explanation
@techdose4u
@techdose4u 3 жыл бұрын
Right 👍🏼
@Jitendrakumar-gb7cn
@Jitendrakumar-gb7cn 2 жыл бұрын
after each printing check the while condition again that you are incrementing for eg after top++ check whether top
@ashish-bisht
@ashish-bisht 2 жыл бұрын
No you cannot, you have to do it one by one while checking condition for each direction. I suggest you to dry run. and also your while condition is also wrong. Dry run on this test case: row: 3, col: 5 6 6 2 28 2 12 26 3 28 7 22 25 3 4 23
@nightmare_9
@nightmare_9 3 жыл бұрын
DAMN bro!! Great Explanation, keep doing this great work!!
@systemforge
@systemforge 3 жыл бұрын
Woah.. what an explanation.. 🔥 amazing ❤️
@summerray1795
@summerray1795 2 жыл бұрын
this is a really good trick , thanks for explaining it to so clearly
@dheerajvikas1135
@dheerajvikas1135 Жыл бұрын
You are a freaking genius!!
@pritishpattnaik4674
@pritishpattnaik4674 2 жыл бұрын
Very much intutive and amazing approach
@sunnithreddy6031
@sunnithreddy6031 3 жыл бұрын
I've worked for 5 hrs and wasnt able to solve this your approach is great and i sloved it with ease. THANK YOU!!!!!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@simrankak7045
@simrankak7045 3 жыл бұрын
This is the best channel for any explainationof code thankyou so much
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@ileshchauhan5483
@ileshchauhan5483 Жыл бұрын
Bro ur way of explaining it with 0,1,2,3 direction solved my every doubt of this question.
@techdose4u
@techdose4u Жыл бұрын
Nice 😊
@sehejwahla410
@sehejwahla410 3 жыл бұрын
Thanks sir . Love your work . Salute from Punjab !!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks paji :)
@pawanchormule2530
@pawanchormule2530 12 күн бұрын
Beautifully explained and clean code
@hatemsaadallah8532
@hatemsaadallah8532 3 жыл бұрын
Amazing explanation! Thank you!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome
@surajmaharana2608
@surajmaharana2608 3 жыл бұрын
Great Explanation, Thank you !!!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@mansiagrawal4039
@mansiagrawal4039 3 жыл бұрын
Depicted the approach very well. Thanks :)
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@garyclark3483
@garyclark3483 2 жыл бұрын
Very good description. Thank you.
@niteenautade
@niteenautade Жыл бұрын
So beautifully explained
@amyanktiwari
@amyanktiwari 3 жыл бұрын
Amazing explanation I got the approach will code it myself ,to get a grasp
@techdose4u
@techdose4u 3 жыл бұрын
Great
@bhavyashah1775
@bhavyashah1775 4 жыл бұрын
Awesome solution!!! Great explanation.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@preetichib2254
@preetichib2254 Жыл бұрын
dhanyawad mitar. helped right on time.
@brandoncazares8452
@brandoncazares8452 Жыл бұрын
Excellent explanation thanks for this.
@CSKAASIPRASANTHA
@CSKAASIPRASANTHA 2 жыл бұрын
Excellent explanation with Clear manner
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@rifathossain2788
@rifathossain2788 Жыл бұрын
Explained well. Thanks.
@surajkumarmohanty4976
@surajkumarmohanty4976 2 жыл бұрын
Brilliant form of explanation 👌👏👍
@techdose4u
@techdose4u 2 жыл бұрын
Thanks
@rakibhasan_
@rakibhasan_ 2 жыл бұрын
Great explanation...! Thank you!
@priyanshshah6126
@priyanshshah6126 Жыл бұрын
Amazing explanation!
@dhirendrakumar4619
@dhirendrakumar4619 2 жыл бұрын
Awesome Explanation Sir
@kirtisachapra9030
@kirtisachapra9030 Жыл бұрын
Great explanation. Thanks a lot!!
@aaryansaha9616
@aaryansaha9616 2 жыл бұрын
awessome expalnation bro, pura ssamjg aagaya
@zensic
@zensic 2 жыл бұрын
Nice! Thanks for sharing!
@subhambanerjee6334
@subhambanerjee6334 3 жыл бұрын
Thanks a lot very well explained I got this question suddenly in an interview after preparing so much on dp and LinkedList tree I got stuck in this I was devastated anyways now I am sure I can solve this every time.
@techdose4u
@techdose4u 3 жыл бұрын
Nice :)
@natashaganjoo4464
@natashaganjoo4464 2 жыл бұрын
which company's interview btw?
@RoopaSri-fp7kh
@RoopaSri-fp7kh 2 ай бұрын
Now I've solved this problem. Thank you
@tusharkumar1984
@tusharkumar1984 3 жыл бұрын
Hey superb video and really helpful , can you please do a video on "Matrix Rotation" , that would help a lot.
@haribk5995
@haribk5995 3 жыл бұрын
really nice brother ! this is one of the best class that I have ever seen.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@mayanktiwari3103
@mayanktiwari3103 Жыл бұрын
so simple explanation for a tricky question like this
@shubhamkechale6940
@shubhamkechale6940 2 жыл бұрын
Your explanation is so easy... Thx..
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😊
@muwnhius
@muwnhius 2 жыл бұрын
amazing!! you make me like algorithms
@shubhambhatt2704
@shubhambhatt2704 Жыл бұрын
Crystal clear explanation. Thanks a lot
@techdose4u
@techdose4u Жыл бұрын
You are welcome!
@riyazshaik864
@riyazshaik864 6 ай бұрын
best explanation in whole youtube
@reshaknarayan3944
@reshaknarayan3944 3 жыл бұрын
Earned a sub today, Thankyou for the effort.
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@mayurkapadnis4265
@mayurkapadnis4265 2 жыл бұрын
excellent explaination!
@modir810
@modir810 Жыл бұрын
I understand completely in an easy way can you tell how we can approach our own like these Matrix problems(transpose...etc)
@pritishpattnaik4674
@pritishpattnaik4674 2 жыл бұрын
Was able to solve all the variations of spiral matrix in Leetcode after watching this video
@siddharth.chandani
@siddharth.chandani Жыл бұрын
Absolute Explaination BUDDY :}
@prabhatracherla3098
@prabhatracherla3098 3 жыл бұрын
Even simpler code with lesser if conditions and without directions mat = [[ 1, 2, 3,], [5, 6, 7], [9, 10, 11], [13, 14, 15]] top, bottom, left, right = 0, len(mat)-1, 0, len(mat[0])-1 while(top left: for i in range(bottom, top-1, -1): print mat[i][left] left += 1
@narendrakumariitb
@narendrakumariitb 2 жыл бұрын
Wow what a neat explanation hats off 👏 thanks. Though I was patiently waiting for while condition😉
@techdose4u
@techdose4u 2 жыл бұрын
Haha 😂 you can apply it now 😜
@InvestmentEducationCommunity
@InvestmentEducationCommunity Жыл бұрын
Awesome explanation
@AADuoDiaries
@AADuoDiaries 3 жыл бұрын
Thank you sir , gratitude to your work 👏
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@nbdevisree2106
@nbdevisree2106 2 жыл бұрын
thanks for the explanation.its helpful
@YashSharma-os9ng
@YashSharma-os9ng Жыл бұрын
thanks u so much man, for such a nice and easy explaination :)
@AtulDislay
@AtulDislay 4 жыл бұрын
Great explanation. Looking forward to more videos and Data Structure series 🙌
@techdose4u
@techdose4u 4 жыл бұрын
Sure :)
@deep.amrutiya
@deep.amrutiya 3 жыл бұрын
Love your work. Would you be able to make video for this ? Largest Rectangle in Histogram
@techdose4u
@techdose4u 3 жыл бұрын
I will make it. But currently I am doing dynamic programming. After that I can do.
@arslanahmed1311
@arslanahmed1311 2 жыл бұрын
Amazing Explanation
@tmiitroorkee1244
@tmiitroorkee1244 2 жыл бұрын
Amazing explaination
@user-je9ji4do5z
@user-je9ji4do5z 5 ай бұрын
i have easily understand great explanation😍😍😍😍😍
@PradeepKumar-eq7kj
@PradeepKumar-eq7kj 3 жыл бұрын
amazing bhai.... your explaination is the always best
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
터키아이스크림🇹🇷🍦Turkish ice cream #funny #shorts
00:26
Byungari 병아리언니
Рет қаралды 28 МЛН
FOOLED THE GUARD🤢
00:54
INO
Рет қаралды 63 МЛН
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27
Solve Any Pattern Question With This Trick!
57:20
Kunal Kushwaha
Рет қаралды 2,3 МЛН
Largest number formed from an array
8:33
Techdose
Рет қаралды 115 М.
Print Matrix Diagonally (Diagonal order)
13:22
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 109 М.
Spiral Matrix - Microsoft Interview Question - Leetcode 54
16:46
Print a given matrix in spiral form | GeeksforGeeks
8:47
GeeksforGeeks
Рет қаралды 188 М.
Number of islands | Leetcode #200
12:44
Techdose
Рет қаралды 175 М.
Print Matrix in spiral form ( 2-D array)
17:25
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 123 М.
Spiral Matrix II - Leetcode 59 - Python
16:02
NeetCodeIO
Рет қаралды 9 М.
터키아이스크림🇹🇷🍦Turkish ice cream #funny #shorts
00:26
Byungari 병아리언니
Рет қаралды 28 МЛН