Trick for spiral matrix traversal

Sdílet
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...

Komentáře • 558

  • @pankajrathi
    @pankajrathi Před 3 lety +140

    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.

  • @PsSarvna
    @PsSarvna Před 3 lety +194

    Yesterday, I got rejected in final round for not solving this problem. That's why I'm here 🙋‍♂️.

  • @OscarMartinez-nt6zn
    @OscarMartinez-nt6zn Před rokem

    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!

  • @premsainoolu8290
    @premsainoolu8290 Před 2 lety +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

  • @doersstuff8067
    @doersstuff8067 Před 2 lety +1

    before watching this video I couldn't believe that i can understand this approach to this problem. You made it so simple.

  • @JuanGarcia-rq9hz
    @JuanGarcia-rq9hz Před 3 lety +9

    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 ^^

  • @kshitizagarwal8389
    @kshitizagarwal8389 Před 3 lety +2

    OMG this one is amazing man! Highly appriciated. Got me another way of approaching a problem Thanks. Kudos!

  • @mohitpandya_2228
    @mohitpandya_2228 Před rokem +2

    The best explanation on entire youtube!! Hats off sir! 💜

  • @mugdhabasak9335
    @mugdhabasak9335 Před 3 lety +4

    the simplicity of this solution just blew my mind!

  • @anantpatel8342
    @anantpatel8342 Před 4 lety +12

    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

  • @akanshamishra6776
    @akanshamishra6776 Před rokem +1

    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.

  • @kritikasingh4698
    @kritikasingh4698 Před 2 lety

    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.

  • @divyanshudwivedi3756
    @divyanshudwivedi3756 Před rokem +1

    You made it look very easy . Thanks a lot !

  • @jinysong2990
    @jinysong2990 Před 3 lety +68

    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

  • @laharibangaru3756
    @laharibangaru3756 Před 3 lety +10

    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. 👏

  • @ARIFAHMAD-cj4xk
    @ARIFAHMAD-cj4xk Před rokem

    Thank you, this is the easiest approach i have seen so far and well explained

  • @techykush7192
    @techykush7192 Před 3 lety +14

    i really like your teaching style ,mind blowing u understood us in a simplest form i have seen ever
    thanks bhaiya 😊😊

  • @JayJayJay007
    @JayJayJay007 Před rokem

    Brilliant explanation, very easy to understand and remember the approach. Big thanks!

  • @MsHappygirl26
    @MsHappygirl26 Před 2 lety +2

    Thank you so much! So easy to understand when you explain it!

  • @sureshgarine
    @sureshgarine Před 2 lety +6

    wow! what a wonderful explanation. saying thanks is not enough. please continue the good work for the community

  • @SenthilKumar-nt2tk
    @SenthilKumar-nt2tk Před 3 lety +2

    U r such an awesome person ..thank you for this code... god bless you

  • @akankshitadutta8842
    @akankshitadutta8842 Před 2 lety

    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!

  • @jisanson
    @jisanson Před 9 měsíci

    the best explanation i've found for the problem, thank you!

  • @chandraprabhat3496
    @chandraprabhat3496 Před 3 lety +4

    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 .

  • @rajatagrawal1999
    @rajatagrawal1999 Před 2 lety

    The way u have explained the concept is amazing. I coded it without any help. Thanks :)

  • @natureone5617
    @natureone5617 Před 3 lety +4

    what a lovely explanation and a very easy approach to traverse a matrix spirally
    thank you and loved to watch more videos

  • @sugandhm2666
    @sugandhm2666 Před 2 lety +15

    Bro you teach the approach and logic so well. Many CZcamsrs simply jump into coding without explanations

  • @hackytech7494
    @hackytech7494 Před 4 lety +7

    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

  • @mrcgaming9306
    @mrcgaming9306 Před 2 lety +1

    this is best explanation I have ever seen Thank you so much sir. I understood everything

  • @avinash7786
    @avinash7786 Před 4 lety +5

    Literally you are a great person..What an explanation..Thank you soooo much.

  • @sindhubandaru55
    @sindhubandaru55 Před 3 lety

    Thank you for your explanation . After watching this I'm able write the program without copying the code

  • @kingmaker9082
    @kingmaker9082 Před 2 lety

    a huge thanks to you . everything is perfect. you saved my day

  • @ShreyaSingh-vr9qi
    @ShreyaSingh-vr9qi Před 4 lety +2

    Your all video tutorials are awesome !!

  • @maheshvenkat1349
    @maheshvenkat1349 Před 2 lety

    Great job in explaining in the reasonable speed and in an very understanding manner! :clap

  • @rahulvarma3004
    @rahulvarma3004 Před 3 lety

    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

  • @irisi3308
    @irisi3308 Před 3 lety +10

    Best explanation ever. I usually don't comment on videos, but this is the best!

  • @ritiksrivastava9069
    @ritiksrivastava9069 Před rokem +1

    It helps me to explore the new way of solving the problem..

  • @nightmare_9
    @nightmare_9 Před 3 lety

    DAMN bro!! Great Explanation, keep doing this great work!!

  • @prajwalpatil9395
    @prajwalpatil9395 Před 3 lety +3

    Soo good ! Legends always make it look soo easy !

  • @paragroy5359
    @paragroy5359 Před 2 lety +1

    Thanks a lot for the video....clear and awesome explanation.....keep making such videos
    They are really helpful

  • @kianaahmadi193
    @kianaahmadi193 Před 2 lety

    Thank u , you explained the problem very well, i was struggling to understand the solution before watching your video

  • @dayanandraut5660
    @dayanandraut5660 Před 3 lety +1

    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

  • @dheerajvikas1135
    @dheerajvikas1135 Před rokem

    You are a freaking genius!!

  • @tanujmishra2313
    @tanujmishra2313 Před 3 lety +7

    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  Před 3 lety +1

      Right 👍🏼

    • @Jitendrakumar-gb7cn
      @Jitendrakumar-gb7cn Před 2 lety

      after each printing check the while condition again
      that you are incrementing for eg after top++ check whether top

    • @ashish-bisht
      @ashish-bisht Před 2 lety

      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

  • @ileshchauhan5483
    @ileshchauhan5483 Před rokem +2

    Bro ur way of explaining it with 0,1,2,3 direction solved my every doubt of this question.

  • @kambalavijay6800
    @kambalavijay6800 Před 3 lety +13

    I never thought it is as simple as this

  • @anantagarwal863
    @anantagarwal863 Před 4 lety

    Amazing, the trick made the problem very easy

  • @shravniwakde1754
    @shravniwakde1754 Před 2 lety +1

    You explained in such a beautiful manner thank you...!!!

  • @summerray1795
    @summerray1795 Před 2 lety

    this is a really good trick , thanks for explaining it to so clearly

  • @pawanchormule2530
    @pawanchormule2530 Před 20 dny

    Beautifully explained and clean code

  • @akki4083
    @akki4083 Před 3 lety +4

    Thanks Bro. You made this question really easy. I was really frustrated. Thanks for the help.

  • @garimachawla775
    @garimachawla775 Před 9 měsíci

    really helpful! THANKYOU

  • @simrankak7045
    @simrankak7045 Před 3 lety +1

    This is the best channel for any explainationof code thankyou so much

  • @YashSharma-os9ng
    @YashSharma-os9ng Před rokem

    thanks u so much man, for such a nice and easy explaination :)

  • @sehejwahla410
    @sehejwahla410 Před 3 lety +4

    Thanks sir . Love your work . Salute from Punjab !!

  • @systemforge
    @systemforge Před 3 lety

    Woah.. what an explanation.. 🔥 amazing ❤️

  • @zensic
    @zensic Před 2 lety

    Nice! Thanks for sharing!

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před 2 lety

    Very much intutive and amazing approach

  • @kirtisachapra9030
    @kirtisachapra9030 Před rokem

    Great explanation. Thanks a lot!!

  • @surajmaharana2608
    @surajmaharana2608 Před 3 lety +2

    Great Explanation, Thank you !!!

  • @rakibhasan_
    @rakibhasan_ Před 2 lety

    Great explanation...! Thank you!

  • @prabhatracherla3098
    @prabhatracherla3098 Před 3 lety

    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

  • @hatemsaadallah8532
    @hatemsaadallah8532 Před 3 lety +3

    Amazing explanation! Thank you!

  • @niteenautade
    @niteenautade Před rokem

    So beautifully explained

  • @siddharth.chandani
    @siddharth.chandani Před rokem +1

    Absolute Explaination BUDDY :}

  • @RoopaSri-fp7kh
    @RoopaSri-fp7kh Před 2 měsíci

    Now I've solved this problem. Thank you

  • @rifathossain2788
    @rifathossain2788 Před rokem

    Explained well. Thanks.

  • @amyanktiwari
    @amyanktiwari Před 3 lety +2

    Amazing explanation I got the approach will code it myself ,to get a grasp

  • @priyanshshah6126
    @priyanshshah6126 Před rokem

    Amazing explanation!

  • @mansiagrawal4039
    @mansiagrawal4039 Před 3 lety +1

    Depicted the approach very well. Thanks :)

  • @saurabh122
    @saurabh122 Před 3 lety

    VERY HELPFUL!!!!!!

  • @dhirendrakumar4619
    @dhirendrakumar4619 Před 2 lety

    Awesome Explanation Sir

  • @garyclark3483
    @garyclark3483 Před 2 lety

    Very good description. Thank you.

  • @riyazshaik864
    @riyazshaik864 Před 6 měsíci

    best explanation in whole youtube

  • @harshitsahu2704
    @harshitsahu2704 Před 5 dny

    just awsome made my code just after first 3 min of viedo .

  • @muwnhius
    @muwnhius Před 2 lety

    amazing!! you make me like algorithms

  • @brandoncazares8452
    @brandoncazares8452 Před rokem

    Excellent explanation thanks for this.

  • @preetichib2254
    @preetichib2254 Před rokem

    dhanyawad mitar.
    helped right on time.

  • @aaryansaha9616
    @aaryansaha9616 Před 2 lety

    awessome expalnation bro, pura ssamjg aagaya

  • @nbdevisree2106
    @nbdevisree2106 Před 2 lety

    thanks for the explanation.its helpful

  • @narendrakumariitb
    @narendrakumariitb Před 2 lety +1

    Wow what a neat explanation hats off 👏 thanks. Though I was patiently waiting for while condition😉

    • @techdose4u
      @techdose4u  Před 2 lety

      Haha 😂 you can apply it now 😜

  • @mayanktiwari3103
    @mayanktiwari3103 Před rokem

    so simple explanation for a tricky question like this

  • @mayurkapadnis4265
    @mayurkapadnis4265 Před 2 lety

    excellent explaination!

  • @pritishpattnaik4674
    @pritishpattnaik4674 Před 2 lety

    Was able to solve all the variations of spiral matrix in Leetcode after watching this video

  • @sunnithreddy6031
    @sunnithreddy6031 Před 3 lety +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!!!!!

  • @user-je9ji4do5z
    @user-je9ji4do5z Před 5 měsíci

    i have easily understand great explanation😍😍😍😍😍

  • @InvestmentEducationCommunity

    Awesome explanation

  • @haribk5995
    @haribk5995 Před 3 lety +11

    really nice brother ! this is one of the best class that I have ever seen.

  • @arslanahmed1311
    @arslanahmed1311 Před 2 lety

    Amazing Explanation

  • @gokulnaathbaskar9808
    @gokulnaathbaskar9808 Před 9 měsíci

    Thank you so much!!!

  • @mohammadsayem2257
    @mohammadsayem2257 Před 2 lety

    Thanks a lot for this.

  • @bhavyashah1775
    @bhavyashah1775 Před 4 lety +1

    Awesome solution!!! Great explanation.

  • @tejastej8537
    @tejastej8537 Před rokem

    super bro 😍 great explaination

  • @shreelakshmi6890
    @shreelakshmi6890 Před 2 lety

    Thanks a ton!!

  • @CSKAASIPRASANTHA
    @CSKAASIPRASANTHA Před 2 lety +1

    Excellent explanation with Clear manner

  • @impatientgaming9868
    @impatientgaming9868 Před 3 měsíci

    Great Explanation

  • @tusharkumar1984
    @tusharkumar1984 Před 3 lety +1

    Hey superb video and really helpful , can you please do a video on "Matrix Rotation" , that would help a lot.

  • @tmiitroorkee1244
    @tmiitroorkee1244 Před 2 lety

    Amazing explaination

  • @pranjalprasad7544
    @pranjalprasad7544 Před 2 lety

    Best solution, easy to understand :)

  • @reshaknarayan3944
    @reshaknarayan3944 Před 3 lety +2

    Earned a sub today, Thankyou for the effort.