Trick for spiral matrix traversal
Vložit
- čas přidán 12. 12. 2019
- 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...
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.
Thanks
Yesterday, I got rejected in final round for not solving this problem. That's why I'm here 🙋♂️.
Now you know it :)
Same here bro
@@rashidixit1168 :o
which comapny?
@@titanofchaos Zoho On-Campus
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!
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
before watching this video I couldn't believe that i can understand this approach to this problem. You made it so simple.
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 ^^
Thanks :)
OMG this one is amazing man! Highly appriciated. Got me another way of approaching a problem Thanks. Kudos!
The best explanation on entire youtube!! Hats off sir! 💜
the simplicity of this solution just blew my mind!
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
Thanks :)
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.
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.
You made it look very easy . Thanks a lot !
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
Nice 😊
3D spiral ata hai kya aapko?
@@lakshaysingla2754 Mujhe toh 2D he Tough laga
@@hhhhhhhhh963 yaar wo to hai but hamare college walo ne 3D spiral de diya test mai karne ko
@Jiny Song on which platform you run the program
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. 👏
Welcome :)
Thank you, this is the easiest approach i have seen so far and well explained
i really like your teaching style ,mind blowing u understood us in a simplest form i have seen ever
thanks bhaiya 😊😊
Welcome 😃
Brilliant explanation, very easy to understand and remember the approach. Big thanks!
Thank you so much! So easy to understand when you explain it!
Welcome :)
wow! what a wonderful explanation. saying thanks is not enough. please continue the good work for the community
Thanks
U r such an awesome person ..thank you for this code... god bless you
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!
the best explanation i've found for the problem, thank you!
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 .
The way u have explained the concept is amazing. I coded it without any help. Thanks :)
what a lovely explanation and a very easy approach to traverse a matrix spirally
thank you and loved to watch more videos
Welcome :)
Bro you teach the approach and logic so well. Many CZcamsrs simply jump into coding without explanations
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
Welcome :)
this is best explanation I have ever seen Thank you so much sir. I understood everything
Literally you are a great person..What an explanation..Thank you soooo much.
Welcome :)
Thank you for your explanation . After watching this I'm able write the program without copying the code
a huge thanks to you . everything is perfect. you saved my day
Your all video tutorials are awesome !!
Thanks :)
Great job in explaining in the reasonable speed and in an very understanding manner! :clap
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
Best explanation ever. I usually don't comment on videos, but this is the best!
Thanks for letting me know :)
It helps me to explore the new way of solving the problem..
DAMN bro!! Great Explanation, keep doing this great work!!
Soo good ! Legends always make it look soo easy !
Thanks 😅
Thanks a lot for the video....clear and awesome explanation.....keep making such videos
They are really helpful
Thank u , you explained the problem very well, i was struggling to understand the solution before watching your video
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
Welcome :)
You are a freaking genius!!
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
Right 👍🏼
after each printing check the while condition again
that you are incrementing for eg after top++ check whether top
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
Bro ur way of explaining it with 0,1,2,3 direction solved my every doubt of this question.
Nice 😊
I never thought it is as simple as this
Nice :)
Amazing, the trick made the problem very easy
You explained in such a beautiful manner thank you...!!!
Welcome :)
this is a really good trick , thanks for explaining it to so clearly
Beautifully explained and clean code
Thanks Bro. You made this question really easy. I was really frustrated. Thanks for the help.
Welcome :)
really helpful! THANKYOU
This is the best channel for any explainationof code thankyou so much
Welcome :)
thanks u so much man, for such a nice and easy explaination :)
Thanks sir . Love your work . Salute from Punjab !!
Thanks paji :)
Woah.. what an explanation.. 🔥 amazing ❤️
Nice! Thanks for sharing!
Very much intutive and amazing approach
Great explanation. Thanks a lot!!
Great Explanation, Thank you !!!
Welcome :)
Great explanation...! Thank you!
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
Amazing explanation! Thank you!
Welcome
So beautifully explained
Absolute Explaination BUDDY :}
Now I've solved this problem. Thank you
Explained well. Thanks.
Amazing explanation I got the approach will code it myself ,to get a grasp
Great
Amazing explanation!
Depicted the approach very well. Thanks :)
Welcome :)
VERY HELPFUL!!!!!!
Awesome Explanation Sir
Very good description. Thank you.
best explanation in whole youtube
just awsome made my code just after first 3 min of viedo .
amazing!! you make me like algorithms
Excellent explanation thanks for this.
dhanyawad mitar.
helped right on time.
awessome expalnation bro, pura ssamjg aagaya
thanks for the explanation.its helpful
Wow what a neat explanation hats off 👏 thanks. Though I was patiently waiting for while condition😉
Haha 😂 you can apply it now 😜
so simple explanation for a tricky question like this
excellent explaination!
Was able to solve all the variations of spiral matrix in Leetcode after watching this video
I've worked for 5 hrs and wasnt able to solve this your approach is great and i sloved it with ease. THANK YOU!!!!!
Welcome :)
i have easily understand great explanation😍😍😍😍😍
Awesome explanation
really nice brother ! this is one of the best class that I have ever seen.
Thanks :)
Amazing Explanation
Thank you so much!!!
Thanks a lot for this.
Awesome solution!!! Great explanation.
Thanks :)
super bro 😍 great explaination
Thanks a ton!!
Excellent explanation with Clear manner
Thanks 😊
Great Explanation
Hey superb video and really helpful , can you please do a video on "Matrix Rotation" , that would help a lot.
Amazing explaination
Best solution, easy to understand :)
Earned a sub today, Thankyou for the effort.
Welcome :)