LeetCode Spiral Matrix Solution Explained - Java

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
    Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
    Preparing For Your Coding Interviews? Use These Resources
    --------------------
    (My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
    AlgoCademy - algocademy.com/?referral=nick...
    Daily Coding Interview Questions - bit.ly/3xw1Sqz
    10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
    Follow My Twitter - / nicholaswwhite
    Follow My Instagram - / nickwwhite
    Other Social Media
    ----------------------------------------------
    Discord - / discord
    Twitch - / nickwhitettv
    TikTok - / nickwhitetiktok
    LinkedIn - / nicholas-w-white
    Show Support
    ------------------------------------------------------------------------------
    Patreon - / nick_white
    PayPal - paypal.me/nickwwhite?locale.x...
    Become A Member - / @nickwhite
    #coding #programming #softwareengineering
  • Věda a technologie

Komentáře • 56

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

    Great.... Thumbs up to the clearity of your explanations!

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

    Thanks this is great explanation and variable naming!

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

    great job dood. keep doing this

  • @samermazraani9011
    @samermazraani9011 Před 3 lety

    very well explained especially descriptive variable names make it easier

  • @flamboyanz
    @flamboyanz Před 4 lety +2

    Good one! It made it very easy! Thank you

  • @dediprakasa2162
    @dediprakasa2162 Před 5 lety +17

    Now I understand where those ifs come from. Thank you!

  • @jugsma6676
    @jugsma6676 Před 4 lety +4

    Of all the videos I watched so far, this one is well explained.

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

    thanks for helping me understand how to solve this problem!!

  • @Jackson_Leung
    @Jackson_Leung Před 4 lety

    Great solution! Very intuitive.

  • @atift5465
    @atift5465 Před 5 lety +15

    I live how you explain so thoroughly and use brute force thats understandable and not too optimal to get! Thanks!!

    • @brentleyrandy4950
      @brentleyrandy4950 Před 2 lety

      you all probably dont give a shit but does anyone know a way to get back into an Instagram account..?
      I was stupid lost my login password. I would love any tricks you can offer me.

    • @kolefabian6264
      @kolefabian6264 Před 2 lety

      @Brentley Randy instablaster :)

    • @brentleyrandy4950
      @brentleyrandy4950 Před 2 lety

      @Kole Fabian I really appreciate your reply. I found the site thru google and im trying it out now.
      Takes quite some time so I will reply here later with my results.

    • @brentleyrandy4950
      @brentleyrandy4950 Před 2 lety

      @Kole Fabian It worked and I finally got access to my account again. I am so happy!
      Thanks so much, you really help me out :D

    • @kolefabian6264
      @kolefabian6264 Před 2 lety

      @Brentley Randy You are welcome :D

  • @Zetta_11
    @Zetta_11 Před rokem

    So cool idea!
    Thank you a lot for your efforts!!!

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

    As always great work sir 👍

  • @li-xuanhong3698
    @li-xuanhong3698 Před 2 lety

    Awesome explanation ! Thanks

  • @somewheresomeone3959
    @somewheresomeone3959 Před rokem

    Great way to understand! Thank you!

  • @satyamgupta6030
    @satyamgupta6030 Před rokem

    what a nice explaination thanks a ton brother. please keep making such videos.

  • @user-vg2wu4rg1h
    @user-vg2wu4rg1h Před rokem

    I dont know anything about coding but the coco powder almonds are really good! Thanks for the suggestion Nick!!

  • @sauravbharti2709
    @sauravbharti2709 Před 3 lety

    That was very understandable.. Thank you

  • @rahulkhatoliya6814
    @rahulkhatoliya6814 Před 3 lety

    Great Explanation ! dude

  • @epp5179
    @epp5179 Před rokem

    Great video! Thank you so much!!!

  • @lifeofme3172
    @lifeofme3172 Před 4 lety

    It's a fun problem. Thanks Nick 😊

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

    Nick is the best!

  • @Shishiraithal
    @Shishiraithal Před 4 lety

    Best explaination..thanx man

  • @favrito495
    @favrito495 Před 3 lety

    You are awesome bro.!! Love from India

  • @MichaelSalo
    @MichaelSalo Před 3 lety

    I attempted to do it in a single loop, with some logic to decide what direction the spiral is moving. It works but took me a while and doesn't perform as well as the above.

  • @PssGameplayER
    @PssGameplayER Před 11 měsíci

    Really great video. Helped a lot to understand the problem and look for a solution. I was able to solve it using the approach you showed in rotating the matrix.

    • @PssGameplayER
      @PssGameplayER Před 11 měsíci

      class Solution {
      fun spiralOrder(matrix: Array): List {
      val result = mutableListOf()
      var l = 0
      var r = matrix.first().size - 1
      val totalSize = matrix.size * matrix.first().size
      while (l

    • @PssGameplayER
      @PssGameplayER Před 11 měsíci

      but looks like your solution is much faster

  • @abisoyelawal9810
    @abisoyelawal9810 Před 5 lety +5

    I like how you use descriptive variable names instead of i and j

  • @anirbansarkar6306
    @anirbansarkar6306 Před 3 lety

    awesome solution

  • @kashafmujeeb3690
    @kashafmujeeb3690 Před 2 lety

    What is the time and space complexity for this solution?

  • @laurawu5146
    @laurawu5146 Před 4 lety

    Feel much better to solve problems while watching your video

  • @GuitaristVoyage
    @GuitaristVoyage Před 2 lety

    can u explain the if check inside whike loop

  • @surajtopal9940
    @surajtopal9940 Před 3 lety

    woooow, it is very simple using boundaries

  • @dineshkumar-kw1ik
    @dineshkumar-kw1ik Před 2 lety

    Can anyone, please explain the time complexity for this algorithm?

  • @yij9010
    @yij9010 Před 4 lety

    love it!

  • @dhruva1221
    @dhruva1221 Před 5 lety

    better than that in geeksforgeeks(where I had left comment to use self descriptive var names would do well) which was better than that of code school where I disliked the logic & var names

  • @ryfarley
    @ryfarley Před 3 lety

    Thanks for this. Also, +1 on chocolate covered almond things.

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

    It would be nice if you can post the solution in Github.

  • @nathann4291
    @nathann4291 Před 5 lety +1

    great work, what's the time complexity?

  • @user-oy4kf5wr8l
    @user-oy4kf5wr8l Před 4 lety +1

    Gooooood!

  • @guntukaramakrishna
    @guntukaramakrishna Před 3 lety

    oh my god.. I am just typing the code continuously after his explanation. It was a nightmare before watching this video. +1 for variable naming. That simply made to write flaw less code.

  • @HR-pz7ts
    @HR-pz7ts Před 11 měsíci

    Thanks

    • @HR-pz7ts
      @HR-pz7ts Před 11 měsíci

      I came back to thank you again orignally I was looking for a solution for spiral matrix 2 and your explanation was so good that I solved a different question with the help of your explanation in this video.

  • @nileshkhimani9315
    @nileshkhimani9315 Před 3 lety

    hwo to treaverse this spiral matrix in O(logn) time?

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

    If you don't want to type the code, you can get it from here github.com/eMahtab/spiral-matrix

  • @nileshkhimani9315
    @nileshkhimani9315 Před 3 lety

    please give a solution in O(logn) time
    please please

  • @arunshinde6487
    @arunshinde6487 Před 2 lety

    A similar and better solution
    class Solution {
    public List spiralOrder(int[][] matrix) {
    List res = new ArrayList();
    if(matrix.length == 0 || matrix[0].length == 0) return res;
    int top = 0;
    int bottom = matrix.length-1;
    int left = 0;
    int right = matrix[0].length-1;
    while(true){
    for(int i = left; i right || top > bottom) break;
    for(int i = top; i right || top > bottom) break;
    for(int i = right; i >= left; i--) res.add(matrix[bottom][i]);
    bottom--;
    if(left > right || top > bottom) break;
    for(int i = bottom; i >= top; i--) res.add(matrix[i][left]);
    left++;
    if(left > right || top > bottom) break;
    }
    return res;
    }
    }