Trick for spiral matrix traversal

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ต.ค. 2024

ความคิดเห็น • 572

  • @pankajrathi
    @pankajrathi 3 ปีที่แล้ว +153

    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.

  • @jinysong2990
    @jinysong2990 3 ปีที่แล้ว +69

    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 ปีที่แล้ว +5

      Nice 😊

    • @lakshaysingla2754
      @lakshaysingla2754 3 ปีที่แล้ว

      3D spiral ata hai kya aapko?

    • @hhhhhhhhh963
      @hhhhhhhhh963 3 ปีที่แล้ว

      @@lakshaysingla2754 Mujhe toh 2D he Tough laga

    • @lakshaysingla2754
      @lakshaysingla2754 3 ปีที่แล้ว

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

  • @PsSarvna
    @PsSarvna 3 ปีที่แล้ว +213

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

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +17

      Now you know it :)

    • @rashidixit1168
      @rashidixit1168 3 ปีที่แล้ว +11

      Same here bro

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +2

      @@rashidixit1168 :o

    • @titanofchaos
      @titanofchaos 3 ปีที่แล้ว +1

      which comapny?

    • @PsSarvna
      @PsSarvna 3 ปีที่แล้ว +6

      @@titanofchaos Zoho On-Campus

  • @premsainoolu8290
    @premsainoolu8290 2 ปีที่แล้ว +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 2 ปีที่แล้ว +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 ปีที่แล้ว +6

    the simplicity of this solution just blew my mind!

  • @laharibangaru3756
    @laharibangaru3756 4 ปีที่แล้ว +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. 👏

  • @anantpatel8342
    @anantpatel8342 4 ปีที่แล้ว +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

  • @tanujmishra2313
    @tanujmishra2313 3 ปีที่แล้ว +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  3 ปีที่แล้ว +1

      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

  • @ileshchauhan5483
    @ileshchauhan5483 2 ปีที่แล้ว +2

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

  • @techykush7192
    @techykush7192 4 ปีที่แล้ว +14

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

  • @sugandhm2666
    @sugandhm2666 3 ปีที่แล้ว +15

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

  • @akanshamishra6776
    @akanshamishra6776 2 ปีที่แล้ว +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.

  • @JuanGarcia-rq9hz
    @JuanGarcia-rq9hz 4 ปีที่แล้ว +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 ^^

  • @prabhatracherla3098
    @prabhatracherla3098 3 ปีที่แล้ว +1

    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

  • @avinash7786
    @avinash7786 4 ปีที่แล้ว +5

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

  • @sunnithreddy6031
    @sunnithreddy6031 3 ปีที่แล้ว +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!!!!!

  • @hackytech7494
    @hackytech7494 4 ปีที่แล้ว +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

  • @ritiksrivastava9069
    @ritiksrivastava9069 2 ปีที่แล้ว +1

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

  • @mrcgaming9306
    @mrcgaming9306 2 ปีที่แล้ว +1

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

  • @irisi3308
    @irisi3308 3 ปีที่แล้ว +10

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

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +2

      Thanks for letting me know :)

  • @natureone5617
    @natureone5617 3 ปีที่แล้ว +4

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

  • @simrankak7045
    @simrankak7045 3 ปีที่แล้ว +1

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

  • @SenthilKumar-nt2tk
    @SenthilKumar-nt2tk 3 ปีที่แล้ว +2

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

  • @jisanson
    @jisanson ปีที่แล้ว

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

  • @dayanandraut5660
    @dayanandraut5660 3 ปีที่แล้ว +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

  • @rahulvarma3004
    @rahulvarma3004 4 ปีที่แล้ว

    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

  • @sindhubandaru55
    @sindhubandaru55 3 ปีที่แล้ว

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

  • @ARIFAHMAD-cj4xk
    @ARIFAHMAD-cj4xk 2 ปีที่แล้ว

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

  • @mohitpandya_2228
    @mohitpandya_2228 2 ปีที่แล้ว +2

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

  • @sureshgarine
    @sureshgarine 3 ปีที่แล้ว +6

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

  • @akki4083
    @akki4083 3 ปีที่แล้ว +4

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

  • @kshitizagarwal8389
    @kshitizagarwal8389 3 ปีที่แล้ว +2

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

  • @VENKAT-n2b
    @VENKAT-n2b 2 หลายเดือนก่อน

    This is the best explanation I have ever seen Thank you so much sir

  • @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!

  • @shravniwakde1754
    @shravniwakde1754 3 ปีที่แล้ว +1

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

  • @MsHappygirl26
    @MsHappygirl26 2 ปีที่แล้ว +2

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

  • @kambalavijay6800
    @kambalavijay6800 3 ปีที่แล้ว +13

    I never thought it is as simple as this

  • @kianaahmadi193
    @kianaahmadi193 2 ปีที่แล้ว

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

  • @subhambanerjee6334
    @subhambanerjee6334 3 ปีที่แล้ว +4

    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.

  • @haribk5995
    @haribk5995 4 ปีที่แล้ว +11

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

  • @CSKAASIPRASANTHA
    @CSKAASIPRASANTHA 2 ปีที่แล้ว +1

    Excellent explanation with Clear manner

  • @deep.amrutiya
    @deep.amrutiya 4 ปีที่แล้ว +8

    Love your work. Would you be able to make video for this ? Largest Rectangle in Histogram

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว +2

      I will make it. But currently I am doing dynamic programming. After that I can do.

  • @modir810
    @modir810 ปีที่แล้ว

    I understand completely in an easy way can you tell how we can approach our own like these Matrix problems(transpose...etc)

  • @MdArif-pc9bz
    @MdArif-pc9bz 2 หลายเดือนก่อน

    The best explanation ever... thanks a lots 👍

  • @harshitsahu2704
    @harshitsahu2704 3 หลายเดือนก่อน

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

  • @shubhamkechale6940
    @shubhamkechale6940 3 ปีที่แล้ว +1

    Your explanation is so easy... Thx..

  • @shivaliraghav8524
    @shivaliraghav8524 2 ปีที่แล้ว +1

    Easy to understand and easy to code after you understand !!

  • @divyanshudwivedi3756
    @divyanshudwivedi3756 2 ปีที่แล้ว +1

    You made it look very easy . Thanks a lot !

  • @ShreyaSingh-vr9qi
    @ShreyaSingh-vr9qi 4 ปีที่แล้ว +2

    Your all video tutorials are awesome !!

  • @kadiyalasaisowmith8739
    @kadiyalasaisowmith8739 3 ปีที่แล้ว +2

    One of best Algorithm i had ever seen

  • @paragroy5359
    @paragroy5359 3 ปีที่แล้ว +1

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

  • @akankshitadutta8842
    @akankshitadutta8842 2 ปีที่แล้ว

    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!

  • @chandraprabhat3496
    @chandraprabhat3496 3 ปีที่แล้ว +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 .

  • @amyanktiwari
    @amyanktiwari 3 ปีที่แล้ว +2

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

  • @rajatagrawal1999
    @rajatagrawal1999 2 ปีที่แล้ว

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

  • @sehejwahla410
    @sehejwahla410 4 ปีที่แล้ว +4

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

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว +1

      Thanks paji :)

  • @godlevelchoker4543
    @godlevelchoker4543 ปีที่แล้ว +1

    bro you earned my respect and a sub 🤩 , i here by acknowledge you as my sensei

  • @pawanchormule2530
    @pawanchormule2530 4 หลายเดือนก่อน

    Beautifully explained and clean code

  • @pritishpattnaik4674
    @pritishpattnaik4674 2 ปีที่แล้ว

    Very much intutive and amazing approach

  • @pritishpattnaik4674
    @pritishpattnaik4674 2 ปีที่แล้ว

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

  • @JayJayJay007
    @JayJayJay007 2 ปีที่แล้ว

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

  • @prajwalpatil9395
    @prajwalpatil9395 3 ปีที่แล้ว +3

    Soo good ! Legends always make it look soo easy !

  • @surajkumarmohanty4976
    @surajkumarmohanty4976 3 ปีที่แล้ว +4

    Brilliant form of explanation 👌👏👍

  • @AbhishekKumar-ff9vg
    @AbhishekKumar-ff9vg 4 ปีที่แล้ว +2

    thank you very much for uploading such videos for us for free

  • @kingmaker9082
    @kingmaker9082 2 ปีที่แล้ว

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

  • @narendrakumariitb
    @narendrakumariitb 2 ปีที่แล้ว +1

    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 😜

  • @PradeepKumar-eq7kj
    @PradeepKumar-eq7kj 3 ปีที่แล้ว +1

    amazing bhai.... your explaination is the always best

  • @RoopaSri-fp7kh
    @RoopaSri-fp7kh 6 หลายเดือนก่อน

    Now I've solved this problem. Thank you

  • @mayanktiwari3103
    @mayanktiwari3103 ปีที่แล้ว

    so simple explanation for a tricky question like this

  • @mansiagrawal4039
    @mansiagrawal4039 3 ปีที่แล้ว +1

    Depicted the approach very well. Thanks :)

  • @summerray1795
    @summerray1795 2 ปีที่แล้ว

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

  • @aldopassio6230
    @aldopassio6230 4 ปีที่แล้ว +11

    Actually you forgot to explain that initial while condition.
    While(top

  • @MadiyarS-s3n
    @MadiyarS-s3n 9 วันที่ผ่านมา

    It was the best solution i found in youtube

    • @techdose4u
      @techdose4u  9 วันที่ผ่านมา

      👌🏽

  • @dheerajvikas1135
    @dheerajvikas1135 ปีที่แล้ว

    You are a freaking genius!!

  • @AADuoDiaries
    @AADuoDiaries 3 ปีที่แล้ว +4

    Thank you sir , gratitude to your work 👏

  • @riyazshaik864
    @riyazshaik864 10 หลายเดือนก่อน

    best explanation in whole youtube

  • @ravipala-q6y
    @ravipala-q6y 9 หลายเดือนก่อน

    i have easily understand great explanation😍😍😍😍😍

  • @shubhambhatt2704
    @shubhambhatt2704 ปีที่แล้ว

    Crystal clear explanation. Thanks a lot

  • @hatemsaadallah8532
    @hatemsaadallah8532 3 ปีที่แล้ว +3

    Amazing explanation! Thank you!

  • @SHASHANKRUSTAGII
    @SHASHANKRUSTAGII 3 ปีที่แล้ว

    best video bhai. Although, there is also a recursive approach to solve this problem, but I liked this.

  • @AvinashKumar-pq6th
    @AvinashKumar-pq6th 3 ปีที่แล้ว +2

    Made it simple. Thanks a lot

  • @kritikasingh4698
    @kritikasingh4698 3 ปีที่แล้ว

    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.

  • @divyanshchaudhary7063
    @divyanshchaudhary7063 ปีที่แล้ว +1

    best explanation on internet

  • @maruthkamath9304
    @maruthkamath9304 2 ปีที่แล้ว

    You forgot to fill in the while condition. Am I right in thinking (left=right=top=down) will be the while condition to terminate the loop?

  • @sameershaik3907
    @sameershaik3907 3 ปีที่แล้ว +1

    Really great explanation bro...
    Please keep making videos on important problems like this....

  • @navdisha4617
    @navdisha4617 2 หลายเดือนก่อน

    Loved the explanation! Thanks

  • @JulianP-ln7xr
    @JulianP-ln7xr ปีที่แล้ว +1

    Thank you so much, that was very useful

  • @shashwatagrawal8412
    @shashwatagrawal8412 3 ปีที่แล้ว +2

    I always struggled with this problem. This is a superb method and great explanation. :)

  • @AkashKumar0201
    @AkashKumar0201 2 ปีที่แล้ว

    Adding one thing, after every loop we have to dir ++;
    unless it never in next direction

  • @surajmaharana2608
    @surajmaharana2608 3 ปีที่แล้ว +2

    Great Explanation, Thank you !!!

  • @muwnhius
    @muwnhius 2 ปีที่แล้ว

    amazing!! you make me like algorithms

  • @raunakagarwal6077
    @raunakagarwal6077 3 ปีที่แล้ว +2

    Super duper explanation sir. 💯🤩

  • @xiangao1194
    @xiangao1194 3 ปีที่แล้ว +2

    Great explain. Did you clarify the condition for while statement? Could it be while top

  • @siddharth.chandani
    @siddharth.chandani 2 ปีที่แล้ว +1

    Absolute Explaination BUDDY :}

  • @abhishek-xv5ow
    @abhishek-xv5ow 2 ปีที่แล้ว +2

    u explained really well :)

  • @rosonerri-faithful
    @rosonerri-faithful 3 ปีที่แล้ว +1

    Can I get the java code,Sir? I'm facing problems..errors executing my code on the IDE

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      You can find on geeksforgeeks

  • @nightmare_9
    @nightmare_9 3 ปีที่แล้ว

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

  • @jitendrasahu7007
    @jitendrasahu7007 2 ปีที่แล้ว +1

    Excellent explanation!

  • @YashSharma-os9ng
    @YashSharma-os9ng ปีที่แล้ว

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